keepcalculator

06 Numbers and Powers

Hyphens vs Underscores in URLs: Which to Use

Card No. 06·81256 · Updated · Standard formula, shown below

Use hyphens (-) in URLs, not underscores (_). Google and most other search engines treat a hyphen as a word separator, so my-page.html is read as two words, while my_page.html is treated as one long word. This simple choice affects readability, SEO, and how your links appear to users.

Background: Why the Debate Exists

In the early days of the web, URLs were often generated from file names, and file names commonly used underscores because they were a safe way to join words without spaces. Many content management systems and developers adopted this habit. However, as search engines evolved, they began parsing URLs to understand page content. Google’s own guidelines and statements from its engineers have consistently recommended hyphens over underscores, and this advice has become the de facto standard for web development.

How Search Engines Read URLs

Search engines use a process called tokenization to break text into words. In a URL, hyphens are treated as word separators, just like spaces in a sentence. Underscores are not. So best-coffee-shops is indexed as best, coffee, shops, whereas best_coffee_shops is indexed as a single token best_coffee_shops. This means a URL with hyphens can help a page rank for the individual words in the slug, while an underscore URL only helps for the exact combined string.

This difference is not just theoretical. Google’s John Mueller has explicitly stated that underscores are not treated as word separators, and that hyphens are the recommended format for URLs. Bing and other search engines follow similar practices.

User Experience and Readability

URLs are visible in search results, browser tabs, and when someone shares a link. A hyphenated URL is easier to read and understand at a glance. Compare:

  • /best-coffee-shops/ – clearly readable as “best coffee shops”
  • /best_coffee_shops/ – looks like a single string, harder to parse

Readable URLs also help users decide whether to click a link. They convey the page topic and create trust. In addition, many users copy and paste URLs into emails or documents; hyphens are less likely to be mistaken for spaces or formatting marks.

How to Choose: Hyphens vs Underscores

For any new URL you create, use hyphens. This applies to:

  • Page slugs (e.g., /about-us/)
  • File names (e.g., report-final.pdf)
  • Image file names (e.g., sunset-beach.jpg)

There is one common exception: if you are working within a system that already uses underscores extensively (like some older CMS or a database-driven app), changing all URLs may cause broken links. In that case, keep the existing structure but use hyphens for any new URLs you create. If you decide to migrate, set up proper 301 redirects from the old underscore URLs to the new hyphenated ones.

Common Problems and Misconceptions

A frequent misconception is that underscores are “more SEO-friendly” because they are treated as a single word and might match a long-tail keyword exactly. In practice, search engines are smart enough to interpret a hyphenated URL as the same phrase, and they also see the words individually, which is almost always better. Another issue is that some users type underscores as spaces, leading to 404 errors. Hyphens avoid this ambiguity.

Another problem arises with copy-pasting: underscores can be hidden when a URL is underlined in text, making it look like a space. This can cause broken links if someone manually retypes the URL.

Comparison with Other Separators

Hyphens are the clear winner, but what about other options? Spaces are automatically encoded as %20 and are not recommended. Plus signs are used in query strings but not in path segments. Slashes separate directories, so they cannot be used within a slug. Dots are allowed but are often confused with file extensions. In short, hyphens are the only separator that is both universally supported and treated as a word delimiter by search engines.

Practical Tips for URL Structure

When crafting a URL, keep these guidelines in mind:

  • Use lowercase letters to avoid case-sensitivity issues.
  • Keep slugs short and descriptive (3-5 words is typical).
  • Use hyphens between words, not underscores.
  • Avoid unnecessary stop words (like “and”, “of”, “the”) unless they are part of a brand name.
  • Use static URLs instead of query parameters when possible (e.g., /products/blue-widget rather than /products?id=123).

Frequently Asked Questions

Do underscores hurt SEO?

They don’t hurt directly, but they miss an opportunity. Because underscores are not word separators, a URL like best_coffee is seen as one word, so it won’t help you rank for “best coffee” as effectively as best-coffee would. The impact is usually small, but it’s an easy fix.

Can I use a mix of hyphens and underscores?

Technically yes, but it’s inconsistent and confusing. Pick one style and stick to it. Hyphens are the standard, so use them everywhere.

What about underscores in query strings?

Query strings (the part after a question mark) are different. Underscores there are fine, but hyphens are still more readable. However, query strings are often not indexed by search engines as part of the page’s main URL, so the impact is minimal.

Should I change my existing underscore URLs?

If the URLs are already indexed and have traffic, changing them can be risky. If you do change, use 301 redirects to preserve ranking. For a new site or new pages, always use hyphens.

Do underscores cause any technical errors?

No, they are valid in URLs. The only issue is readability and how search engines interpret them. Some older systems might have issues, but modern browsers handle both fine.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →