Cepheids obey a period-luminosity relationship. To establish this, you can observe a set of Cepheids at the same distance (e.g. in the Magellanic Clouds).
However, to use this relationship to estimate the distances of more distant Cepheids it must be calibrated. In other words, it is not enough to know the slope of the period-luminosity relationship, we need to know the absolute luminosities (not just brightnesses) of some nearby Cepheids.
Unfortunately, up till recently, even the nearest Cepheids were too far away to precisely measure a trigonometric parallax, so the way it worked was to find Cepheids in clusters with other stars and use the Hertzsprung-Russell diagram of the other stars to estimate the distance and hence luminosity of the calibrating Cepheids.
With space-based parallax measurements (e.g. Hipparcos-based parallaxes, studied in Feast & Catchpole 1997) it has now become possible to attempt to set the zeropoint of the Cepheid period-luminosity relationship using parallax measurements for the nearest examples. A massive increase in precision will become possible with the release of the Gaia satellite astrometry next year.
Cepheids are very bright stars that can be identified by their variability in distant galaxies (in this case, distant means up to about 100 million light years, but not further than that). Their period gives their luminosity (from the calibrated relationship) and their measured brightness combined with the luminosity tells you how far away they are.
Update: The Cepheid period-luminosity law has been recalibrated by using HST to measure the photometric periods of Cepheids in open clusters and then using Gaia EDR3 astrometry to estimate the distances of the clusters using averaged trigonometric parallaxes for large numbers of ordinary stars in those clusters (see Riess et al. 2022). The new calibration reinforces the notion of a "Hubble tension" between values for $H_0$ found from the nearby and distant universe.