Hyphens, Dashes, and Underscores

How hyphens, dashes, and underscores differ, what converting between them changes, and when the result stays readable after copying, searching, or sharing.

Hyphens, dashes, and underscores all look like short horizontal lines, but they are different characters with different jobs. A tool that swaps one for another changes the stored text, not just its appearance. Common examples are turning spaces into underscores, double hyphens into an em dash, or hyphens into underscores for a filename. This review covers what each conversion changes, where it helps, and where it can break things.

Is the transformation suitable for your use?

Converting between these characters is worthwhile when the destination has clear rules for them. Prose benefits from correct dashes. Code identifiers often require underscores. URLs and command-line flags conventionally use hyphens. The main benefit is text that follows the conventions its readers or software expect. The main tradeoff is that a blanket replacement cannot tell a word-joining hyphen from a minus sign, a range, or a command option. It will convert all of them alike.

  • Prose for human readers: use hyphens inside compound words, en dashes for ranges, and em dashes for breaks in a sentence.
  • Code identifiers such as variable and function names: underscores are usually safe; hyphens usually are not.
  • URL paths, CSS class names, and command-line options: hyphens are the common convention.
  • Filenames: both usually work, but stay consistent within a project.
  • Data fields, commands, and anything typed into a terminal: keep the plain keyboard hyphen-minus unless the format explicitly calls for something else.

Plain text is preferable when you cannot check how the destination handles typographic punctuation. The same applies when the text will be parsed by software rather than read by people, and when it may be searched or edited by others who will type the plain keyboard characters.

The characters involved

Character | Unicode code point | Typical use
Hyphen-minus (-) | U+002D | The keyboard character; hyphenation, minus in code, command flags
Hyphen (‐) | U+2010 | Typographic hyphen distinct from minus
Non-breaking hyphen (‑) | U+2011 | Hyphen that prevents a line break at that point
Soft hyphen | U+00AD | Invisible unless a line breaks there
Figure dash (‒) | U+2012 | Dash the width of a digit, as in phone-style number groups
En dash (–) | U+2013 | Ranges and connections, such as 10–20 or a New York–London flight
Em dash (—) | U+2014 | Breaks or interruptions in a sentence
Minus sign (−) | U+2212 | Mathematical minus
Low line, or underscore (_) | U+005F | Joining words in identifiers and filenames

How long each line appears depends on the font. Some fonts draw the hyphen-minus and en dash at similar widths, and not every font includes a glyph for less common characters such as U+2010. When a glyph is missing, a fallback font or a placeholder box may appear instead. Two lines that look alike can still be different characters, so judge a conversion by the code points it produces, not by how it looks on one screen.

What a conversion actually changes

These tools perform character substitution. They replace one stored code point with another, or replace a sequence such as two hyphens with a single dash. They do not reverse or mirror text, and they do not apply a visual style. That makes them different from formatting. An underscore character is part of the text. An underline is presentation, applied by a word processor or CSS, and it disappears when the text is copied as plain text.

Input:                     well-known
Hyphen to underscore:      well_known

Input:                     pages 10-20
Hyphen to en dash:         pages 10–20

Input:                     wait--what
Double hyphen to em dash:  wait—what

Input:                     my file name.txt
Spaces to underscores:     my_file_name.txt

In each example only the punctuation or space changes, and the letters stay as they are. The inputs contain no combining marks or multi-code-point emoji, so nothing is at risk of splitting. Read the outputs literally: they show what a correct substitution should produce, not the measured output of a particular tool.

Context is the decisive limitation. A rule that turns every hyphen-minus into an en dash also changes negative numbers, dates written with hyphens, and option flags such as -v. Many word processors convert double hyphens to an em dash automatically as you type. Pasted text can therefore already contain dashes you did not intend.

Hyphen vs underscore

In prose, the hyphen joins compound words and the underscore has no standard role. In code, the difference matters more. Many programming languages, including C, Python, and JavaScript, read a hyphen inside a name as subtraction. That is why snake_case, with underscores, is common for identifiers. Kebab-case, with hyphens, is common in CSS class names, URL paths, and command-line option names, where hyphens are allowed.

For URLs, Google's published guidance on URL structure recommends hyphens rather than underscores to separate words. How other search engines treat underscores was not verified here. Underscores can also be hard to see when text is underlined, as links often are, which makes an underscored address easy to misread or mistype.

Editing behavior also differs. In many editors, double-clicking selects an underscored name as a single word and splits a hyphenated one at the hyphen. This varies by application, so check the editors your readers actually use.

Hyphen vs dash

Dashes are longer than hyphens and do a different job. A hyphen joins parts of a word or compound. An en dash shows a range or a connection between two things. An em dash sets off a phrase or marks an interruption. The true minus sign is a separate character used in mathematics. US style guides disagree on whether to put spaces around em dashes. Choose one style and apply it consistently, rather than relying on a tool's default.

Will the result stay readable and usable after copying or sharing?

Copy and paste usually carries the exact Unicode characters, but the destination can still change or reject them. Systems limited to ASCII or a legacy encoding may display replacement characters or strip the dash. Autocorrect in the receiving app may convert the punctuation again. A command copied from a formatted document with an en dash in place of a hyphen-minus will not be read as an option flag by a shell.

Search and find features compare code points. A search for a term typed with a keyboard hyphen may not match text containing a non-breaking hyphen or an en dash unless the tool normalizes punctuation, and tools differ on this. Soft hyphens and non-breaking hyphens can also cause confusing edits, because the soft hyphen is usually invisible and the non-breaking hyphen looks like an ordinary one.

Screen readers handle these characters differently from one product to another, and the result depends on the user's punctuation verbosity setting. A dash may be announced, paused on, or skipped. Underscores between words may be read aloud as "underscore" or may run the words together. No screen reader testing was supplied for this review, so check the specific assistive technology your audience uses rather than assuming one behavior.

Text mixing right-to-left and left-to-right scripts adds another variable. The Unicode bidirectional algorithm treats the hyphen-minus, en dash, and underscore as neutral or separator characters. Their displayed position depends on the surrounding text and can end up on an unexpected side. The stored order does not change, but what readers see can, so preview mixed-direction text in its destination.

Keep a plain-text equivalent that uses only the keyboard hyphen-minus whenever the text will be used as code, a command, a data value, a filename on a shared system, or a search term. The same applies whenever it will pass through a system you have not tested.

Gaps in the evidence

No documentation for any specific converter, platform test results, or assistive technology measurements were supplied. The guidance above therefore rests on Unicode character definitions and widely documented conventions, not on verified tool behavior. Nothing here describes how any particular online tool handles privacy or data retention, and that should not be inferred from a tool's appearance or marketing.

Checklist before applying a conversion

  • Identify the destination: prose, code, URL, filename, command, or data field.
  • Confirm the conversion targets only the cases you mean, not minus signs, ranges in code, or option flags.
  • Check the output's code points, not just its look in one font.
  • Paste the result into the real destination and test search, editing, and display there.
  • Test with the assistive technology and settings your audience uses, if accessibility matters.
  • Keep a plain hyphen-minus version for anything machines will parse.