Emphasis and Italics

Bold and italic are the two forms of emphasis that show up in almost every document, and their syntax amounts to two or three characters. What makes them harder than they look is that they obey the same “delimiter” rules as headings and lists: a marker has to touch the text on the inside to work, a marker with a space next to it does nothing at all, and a marker at the start of a line turns into a list instead. This page explains how * and _ differ, when nesting works, and where inline code takes priority over emphasis.

After this page you should be able to write italics, bold, and bold italic in either style, explain why an underscore behaves differently from an asterisk inside a word, and diagnose the three or four reasons a pair of asterisks sometimes shows up on the page as plain text.

Syntax

The number of markers sets the strength of the emphasis. One marker is italic, two are bold, three are bold italic, and the marker character can be an asterisk or an underscore:

*italic* or _italic_

**bold** or __bold__

***bold italic*** or ___bold italic___

The parser turns those three lines into three paragraphs:

<p><em>italic</em> or <em>italic</em></p>
<p><strong>bold</strong> or <strong>bold</strong></p>
<p><em><strong>bold italic</strong></em> or <em><strong>bold italic</strong></em></p>

Notice that the output contains two different tags: italics become an emphasis element (<em>) and bold becomes a strong element (<strong>). They are separate tags rather than one tag with a style, which is why a renderer is free to show italics in a different typeface and bold in a heavier weight of the same one. Browsers do exactly that: <em> usually means an italic serif, <strong> a heavier upright serif.

Asterisks and underscores

For almost every piece of text the two markers are interchangeable. There is exactly one case where they are not, and it is the case that comes up most often in practice: inside a word.

CommonMark allows an asterisk to open emphasis in the middle of a word, but not an underscore. The reason is that underscores are common inside identifiers, so treating every pair of underscores as emphasis would break far too much ordinary text:

text_italic_text and snake_case_name

text*italic*text
<p>text_italic_text and snake_case_name</p>
<p>text<em>italic</em>text</p>

The first line comes out unchanged: snake_case_name keeps its underscores, which is exactly what you want for a variable name. The second line is italic in the middle of the word, because the asterisk is allowed there. The same rule applies to the double underscore, so some__bold__thing stays literal as well.

The practical consequence is that an underscore only works when the text it wraps is a word of its own, with a space, a punctuation mark, or the edge of the line on the outside:

word _italic_ word

(_italic_)
<p>word <em>italic</em> word</p>
<p>(<em>italic</em>)</p>

Nesting emphasis

Emphasis can contain other emphasis. The markers are matched by count, so the inner pair closes first and the outer pair wraps the result:

**bold with *italic* inside**

*italic with **bold** inside*
<p><strong>bold with <em>italic</em> inside</strong></p>
<p><em>italic with <strong>bold</strong> inside</em></p>

Nesting is worth using sparingly. Two levels of emphasis inside one another is already at the limit of what a reader can take in; three levels is a sign that the sentence should be split instead.

Inline code and emphasis

A code span takes priority over everything around it. Its content is literal: markers inside the backticks are never read as emphasis, which is exactly why identifiers are the safe place to put a variable name that contains an underscore or an asterisk:

Use `snake_case_name` as the variable name.
<p>Use <code>snake_case_name</code> as the variable name.</p>

The relationship works in both directions. A code span can sit inside emphasis, and the emphasis still applies to the whole run:

*text with `code` inside*
<p><em>text with <code>code</code> inside</em></p>

So if a variable name has to be italic, the safest way to write it is to wrap the code span in the emphasis markers, rather than to emphasise the identifier with underscores, which cannot open emphasis inside a word in the first place.

Recommendations

  • Use emphasis semantically: italics to mark a term or a title, bold to mark what matters most.
  • Keep it rare. Bold in more than two or three places per paragraph trains the reader to skip it.

Emphasis marks what the reader is most likely to miss; it is not a layout tool. Once every sentence carries a bold phrase, the bold phrases stop meaning anything. A better way to point at the important part is often structural: split the sentence, put it on its own line, or give it its own paragraph. Italics suit terms, titles, and short asides, while bold suits conclusions and the one action the reader must not miss.

Common pitfalls

SourceWhat rendersWhy
text_italic_textliteral textan underscore cannot open emphasis inside a word
some__bold__thingliteral textthe same rule applies to the double underscore
2*3*42<em>3</em>4the asterisk sits between digits, so it is read as emphasis
* italic at the start of a linea bullet lista marker plus a space is a list bullet
some * italic * textliteral textemphasis markers cannot have a space on the inside
*open in one paragraph, close* in the nextliteral textemphasis cannot cross a paragraph boundary

Exercises

Rewrite the sentence below in Markdown. The word “Note” must be bold, the words “must not” must be italic, and the variable name must stay visible exactly as written, without being turned into emphasis.

Note: snake_case_name is a variable name and must not be used as emphasis markers.
BoldItalicsInline code

Approach:

Bold uses a pair of double asterisks and italics a pair of single asterisks. The variable name is the delicate part: it already contains underscores, and an underscore cannot open emphasis inside a word, but the safe and unambiguous way to keep it intact is to mark it as inline code, whose content is never parsed as emphasis.

Steps:

  1. Write the lead-in as **Note** to make it bold.
  2. Write the warning as *must not* to make it italic.
  3. Wrap the variable name in backticks so that its underscores survive as written.
  4. Check the result: the lead-in is bold, the warning is italic, and the variable name appears in a monospaced typeface with both underscores intact.

Answer:

**Note**: `snake_case_name` is a variable name and *must not* be used as emphasis markers.

Summary

You should now be able to write italics, bold, and bold italic in either marker style, explain that the only real difference between * and _ is what happens inside a word, and recognise the reasons a pair of asterisks survives as literal text: a space on the inside, a bullet list at the start of the line, or an opening marker in a different paragraph. You should also know that inline code always wins over emphasis, which makes it the reliable way to show an identifier. From now on, when you reach for emphasis while editing a document, you will reach for it less often, and leave the blank space and the structure of the page to carry more of the meaning.

Found an issue with this content?

Tell us what could be improved.