Illustration of two web addresses compared, one joined with hyphens and one with underscores

Text & writing

Hyphens vs. Underscores in URLs

Should a web address use learn-piano-chords or learn_piano_chords? The short answer for public web pages is hyphens. This guide explains why, and the situations where underscores are still the right choice.

Ready to try the tool this guide describes?

Why hyphens are the convention

Google’s own guidance on URL structure recommends hyphens to separate words in addresses, because hyphens are treated as word separators while underscores are not reliably treated that way. Hyphens are also easier to see in links, which are often shown underlined — an underline can hide an underscore entirely.

Side by side

Side by side comparison
Hyphen (my-page)Underscore (my_page)
Read as separate words by search enginesYesNot reliably
Visible in an underlined linkYesOften hidden
Common for public web pagesYesRare
Common for code identifiers and file namesSometimesYes

When underscores make sense

  • Variable names, database fields, and identifiers in programming languages where hyphens are not allowed.
  • File names in systems or teams that already use underscores consistently.
  • Existing URLs that already use underscores and are well linked — changing them means redirecting every address.

Consistency matters most

Whichever separator you pick for a site, use it everywhere. Mixing styles makes addresses harder to guess and type, and can lead to near-duplicate pages. Spaces should never appear in a slug; they are encoded as %20 and look broken when shared.

Hyphens vs. Underscores FAQ

Are hyphens or underscores better in URLs?
Hyphens, for public web pages. Search engines treat them as word separators and they stay visible in underlined links.
Do underscores hurt search rankings?
They are not a penalty, but words joined with underscores may not be recognised as separate words, which is why hyphens are recommended.
Should I change existing URLs from underscores to hyphens?
Usually not worth it for established pages. If you do, set up permanent redirects from every old address.
When should I use underscores?
For code identifiers, database fields, and file-naming systems that already use them.
Can a URL contain spaces?
Not directly. Spaces are encoded as %20, which looks messy, so slugs use hyphens instead.

Related guides

Open the tool

Jump into URL Slug Generator when you are ready to process your files.

← Back to all guides

More from Looty

Explore Looty’s Ecosystem

Discover more ways Looty can help you learn, organize, create, and make an impact.