There are good and direct connections from to Karlovy Vary from Prague by bus; with around 8 buses departing every day and journey times starting from 2hrs 15mins, this seems to be the most convenient form of public transport. The timetables are normally only written in Czech, so go to a tourist information office if in doubt to book your ticket. Timetables vary according to whether it is a week day, weekend or public holiday.
Trains from Prague go a rather indirect route and therefore take longer than the bus, with an average journey time of around 4hrs.
All public transport routes tend to end in the less attractive north of the city; head towards the south for the spa area and picturesque tourist spots!
You may decide to hire a car to complete the journey, but rumour has it that the route between Prague and Karlovy Vary along the E48 is quite a dangerous one due to frequent careless driving, so please take care! It's also worth knowing that there are strict parking restrictions in the centre and therefore finding somewhere to house your car whilst visiting can prove very difficult.