The below information is from The Citizens Advice Bureau website.
Free treatment is available, but not automatically for every person who enters the UK from abroad. Emergency, compulsory psychiatric, and contagious or infectious disease treatments are free. HIV diagnosis is free but treatment may not be.
As with UK residents, some NHS treatments have to be paid for (such as dentists and opticians), although help is available if you can not afford to pay. People living or working in the UK are entitled to free treatment, but so are people who may be taken ill whilst in the UK for a short stay. Some countries have an arrangement where UK residents can get free medical treatment, and residents of that country can get the same in the UK - this is called a reciprocal agreement.
If you cannot pay for NHS treatment, urgent treatment will still be carried out on the NHS, but you will have to return home for continued treatment. If the need is not urgent, NHS treatment may be offered, but not for free.
Unless you have come to the UK specifically for medical reasons, this entitlement for free treatment extends to GP services, community nurses, midwifery and ambulances, although a GP may require proof of how long you intend to stay in the UK.
For more information about NHS charges for people from abroad, see NHS charges for people from abroad.
For more information about NHS services in general, see NHS and local authority health services.