Vrhnika lies at the southwest end of the Ljubljana Marsh near the sources of the Ljubljanica River, where the Ljubljana Basin opens up between the foot of Ljubljana Peak (Slovene: Ljubljanski vrh, 819 meters or 2,687 feet) and Ulovka Hill (801 meters or 2,628 feet). The territory of the town extends south onto the Logatec Plateau (Slovene: Logaška planota), where the Big and Little Drnovica Collapse Sinkholes (Slovene: Velika Drnovica, Mala Drnovica) are found. A rich network of springs and streams originates and joins near the town to form the source of the Ljubljanica.
The settlement at the location of today's Vrhnika was attested in antiquity as Nauportus in Latin, and as Ναύποντος and Νάμπορτος in Greek. Medieval attestations of the name include de superiory Laybaco in 1300, Oberlaybach in 1308 (and Ober Laybach in 1309), and Vernich in 1481, corresponding to the modern Slovene name. In the past, the town was known as Oberlaibach in standard German. The Slovene name is probably a compound of vrh 'top, summit' + nika or nikve 'creek, spring', referring to the source of the Ljubljanica River. The Latin name Nauportus is a compound of navis 'boat' + portus 'transfer', referring to a place where cargo had to be transferred from boats to pack animals or carts along a trade route. A mythological reinterpretation of the Latin name as referring to the portage of a boat itself (specifically, the Argo) appears in Pliny the Elder's Natural History.
Vrhnika became a market town and was among the wealthiest towns in Carniola up to the early 18th century, when it started to lose importance. Nevertheless, it remained one of main transportation junctions in Inner Austria because of its strategic location on the crossroads between the trade routes from Trieste to Vienna and from Rijeka to Klagenfurt. The development of the town was strongly impaired by the construction of the Austrian Southern Railway in the 1840s, which bypassed it. From then on, it started losing importance, becoming a satellite town of Ljubljana, which has remained up to this day.
Vrhnika is the site of a mass grave from the period immediately after the Second World War. The Pikec Valley Mass Grave (Slovene: Grobišče pri Pikčevi dolini) is located at the bottom of a sinkhole southwest of the town, on Sveč Hill near the Vojc house. It contains the remains of six German prisoners of war that were murdered in May 1945.