Hyphens and dashes in WordPress

I’ve often been uncertain about what WordPress does with one or more hyphens in various contexts, and even looking at the code of wptexturize is that useful — not all code is poetry.

One or more hyphens can produce a single hyphen (-), an en dash (–) or an em dash (—), but it’s not entirely straightforward.

TL;DR

A single hyphen becomes an en-dash if surrounded by spaces. Otherwise, it remains a hyphen.

Double hyphens become an em-dash if surrounded by spaces. Otherwise, they become an en-dash.

Triple hyphens always become an em-dash.

Common usage

Number ranges with en-dashes require double hyphens, as in 5–6. Otherwise, you’ll get a hyphen, like 5-6.

Em-dashes used as punctuation—normally without any spaces around—need to be entered as triple hyphens. If used with spaces around — which is not the common usage, however — double or triple hyphens work the same.

See — for example — How to Use Em Dashes (—), En Dashes (–), and Hyphens (-) on Merriam-Webster.

Test tables

Single hyphens

InputOutputResultNote
-en dashalone
word-wordword-wordhyphensurrounded by letters
word - wordword – worden dashbetween words with spaces
word- wordword- wordhyphenspace after
word -wordword -wordhyphenspace before
5-55-5hyphenbetween digits
5 - 55 – 5en dashbetween digits with spaces

Double hyphens

InputOutputResultNote
--em dashalone
word--wordword–worden dashsurrounded by letters
word -- wordword — wordem dashbetween words with spaces
word-- wordword– worden dashspace after
word --wordword –worden dashspace before
5--55–5en dashbetween digits
5 -- 55 — 5em dashbetween digits with spaces

Triple hyphens

InputOutputResultNote
---em dashalone
word---wordword—wordem dashsurrounded by letters
word --- wordword — wordem dashbetween words with spaces
5---55—5em dashbetween digits
5 --- 55 — 5em dashbetween digits with spaces

Comments

One response to “Hyphens and dashes in WordPress”

  1. René Seindal avatar
    René Seindal

    @blog Dashing en and em dashes.

Leave a Reply

Your email address will not be published. Required fields are marked *