As a front-end developer you'll inevitably have to work with copy or text. Whether you're writing your own copy or it is provided to you, it is important to have proper grammar by using the right characters. For this article we'll take a look at hyphens and dashes.
If you take a look through your keyboard, you might think there's only one type of hyphen or dash, and that's understandable since there is only one key. However, there are at least four different types of dashes that you'll typically encounter, and each has very different context.
When you hit that hyphen key on your keyboard, what you get is the hyphen. The hyphen's purpose is for compound words such as "cross-platform", "fine-tune", or "high-resolution".
A similar use is when you start a new line and break in the middle of a word. An example of this would be:
In 1995, Brendan Eich developed a com-
puter language called JavaScript.
The en dash (–) is a little bit wider than your standard hyphen (about the size of an n). The en dash tends to be more used with data or statistics.
One use of the en dash is to display a range. Here are some examples:
Another use for en dash is when two terms are connected:
Lastly, we can use en dash to display scores:
So, how do you get the en dash into your copy? You could:
–
The em dash (—) is a bit wider than the en dash (about the size of an m). The em dash tends to be used as replacements for other punctuation.
Here's an example where we use it to replace a comma:
Next let's replace a colon:
Finally, we'll replace parentheses:
How do you get the en dash into your copy? Just like the en dash:
—
Finally, when you're working with mathematical expressions, technically it's more accurate to use the minus symbol (−) instead of the hyphen:
However, I haven't seen this used commonly outside of mathematics publications, and screen readers can interpret a hyphen correctly given a math related context. You can use the HTML entity for this: −
Now that you know about these different dashes and have seen how they're used, you won't be able to unsee it. Next time your working on your copy, take that extra moment to see where these might fit in.