Markdown cheatsheet · Text color

Coloring text in markdown

Markdown has no syntax for coloured text, so every method is a workaround tied to where the file is read. Here's what works where, and why colour is usually the wrong tool.

The short answer

Markdown has no syntax for coloured text. None. Every method is a workaround, and which workaround works depends entirely on where the file will be read. The honest version of this page is a decision by target, not a snippet to copy.

Pick your target

Where it rendersWhat works
A website, docs site, most generatorsAn HTML <span> with a style
GitHub / GitLabNothing reliable. HTML styles are stripped. See below.
Jupyter notebooksThe <span style> or <font color>
ObsidianHTML span, or ==highlight== for a background
Discord / SlackA code-block trick, and only some colours. Separate rules.
Strict CommonMarkNothing. HTML is off.

The one that works where HTML is allowed

On a website, a docs generator or anywhere raw HTML survives, wrap the text in a span with an inline style.

You type
This is <span style="color:#c0392b">important</span> text.
You get

This is important text.

Use a hex code, an rgb(), or a named colour like red. The old <font color="red"> tag still works in many renderers but is deprecated; the span is the current form.

GitHub, specifically, because it's the most-asked and the answer is "you basically can't"

GitHub strips style attributes for security, so the span above renders as plain text on GitHub. There is exactly one place GitHub renders colour: inside a math block, via a LaTeX colour command. It's a genuine hack, and it's the reason this question has a million views.

You type
$\color{red}{\textsf{This shows red on GitHub}}$
You get

This shows red on GitHub

Be honest about this one. The LaTeX trick works, but it renders your text as a maths formula: no wrapping, no clickable links inside it, and odd spacing. For a one-word label it's fine. For a sentence it looks broken. The thin pages that rank for this question show you the trick and don't tell you it falls apart past a few words.

The better instinct: don't colour the text

Most "how do I make this red" questions are really "how do I make this stand out", and colour is the least portable way to do it. What travels everywhere, GitHub included:

  • Bold for emphasis: bold & italic.
  • A callout for a warning or a note, which carries colour and meaning: callouts.
  • Highlighting where it's supported: highlight.
  • An emoji as a colour cue that renders literally everywhere: a red circle before a line reads as "stop" without any colour syntax at all.

Colour also fails a real chunk of your readers: it's invisible to screen readers and hard to distinguish for the colour-blind. If the meaning is only in the colour, some people miss it entirely. Pair it with a word.

Common questions

Why doesn't my coloured text show on GitHub?

GitHub removes the style attribute. Only the LaTeX-in-math trick shows colour there, with the caveats above.

Can I set a background colour instead?

Same rules: <span style="background:#ff0"> where HTML is allowed, nothing on GitHub. In Obsidian, ==text== gives a highlight.

How do I colour a whole heading?

Wrap the heading text in the same span. On a heading the LaTeX trick is more disruptive, so it's rarely worth it.

Can I colour text in a table cell?

Yes, the span works in a cell wherever it works elsewhere, since inline HTML is allowed there.

Related syntax

· All markdown guides

Less syntax. More writing.

Download maxdown

Free · no account · macOS, Windows & Linux