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 renders | What works |
|---|---|
| A website, docs site, most generators | An HTML <span> with a style |
| GitHub / GitLab | Nothing reliable. HTML styles are stripped. See below. |
| Jupyter notebooks | The <span style> or <font color> |
| Obsidian | HTML span, or ==highlight== for a background |
| Discord / Slack | A code-block trick, and only some colours. Separate rules. |
| Strict CommonMark | Nothing. 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.
This is <span style="color:#c0392b">important</span> text.
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.
$\color{red}{\textsf{This shows red on GitHub}}$This shows red on GitHub
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.