Skip to main content

Markdown Text Color

Markdown has no color syntax. Each platform has its own workaround, and the one most tutorials teach, an HTML span with a style attribute, is exactly the one GitHub throws away. Here is what works where.

Short answer

Where raw HTML is allowed (Obsidian, VS Code, most static site generators), use <span style="color: red">text</span>. GitHub strips style, so there use LaTeX: $\color{red}{\text{text}}$, or <mark> for a highlight. Discord needs an ansi code block. Slack and Reddit have no text color at all.

Method 1: The HTML <span> Tag

Markdown passes raw HTML through, so a <span> with a style attribute colors any run of text. The color can be a CSS name (red, tomato), a hex value (#2563eb), or a function (rgb(220, 38, 38), hsl(0, 80%, 50%)).

A named CSS color

Markdown

<span style="color: red">This text is red.</span>

Preview

This text is red.

A hex value: 3, 6, or 8 digits

Markdown

<span style="color: #2563eb">This text is blue (#2563eb).</span>

Preview

This text is blue (#2563eb).

Several colors in one paragraph

Markdown

<span style="color: #10b981">Green</span>, <span style="color: #f59e0b">orange</span>, and <span style="color: #8b5cf6">purple</span> in one line.

Preview

Green, orange, and purple in one line.

Background color - the same span, a different property

Markdown

<span style="background-color: #fef3c7; color: #92400e">Highlighted text</span> uses background-color.

Preview

Highlighted text uses background-color.

Works in: Obsidian, the VS Code preview, Jekyll, MkDocs, Eleventy, Astro, and JupyterLab. Stripped by: GitHub, GitLab, and PyPI, which keep the span but delete its style. Off by default in Hugo, which drops all raw HTML until you set markup.goldmark.renderer.unsafe = true.

In MDX, the style has to be an object

Docusaurus and Next.js parse MDX, where every HTML-looking tag is JSX. JSX expects style as an object with camelCased properties, so the string form above fails. Docusaurus documents the same conversion.

<span style={{ color: "red" }}>Red text in MDX</span>
Don't rely on color alone. Color-blind readers and screen readers miss it. Pair it with bold, an icon, or a word like “Warning:”, and check contrast in both light and dark themes, since a red that reads well on white can vanish on a dark background.

Method 2: LaTeX Color on GitHub

GitHub renders math in README files, issues, pull requests, discussions, and wikis, and math has its own color command. Wrap the text in $...$ and use \color{name}{\text{your text}}. The \text{} keeps the spaces and an upright font; without it, math mode drops spaces and italicizes every letter.

Named colorGitHub, GitLab

Markdown

$\color{red}{\text{Red text on GitHub}}$

How it renders on GitHub

Red text on GitHub
Hex colorGitHub, GitLab

Markdown

$\color{#16a34a}{\text{Exact hex color}}$

How it renders on GitHub

Exact hex color
Colored formulaGitHub, GitLab

Markdown

$\color{blue}{a^2 + b^2 = c^2}$

How it renders on GitHub

a² + b² = c²
Checked on GitHub in October 2026. GitHub's MathJax now outputs native MathML, and \color becomes a mathcolor attribute. Hex values render exactly. Seven names (red, blue, green, orange, yellow, purple, gray) are remapped to GitHub's theme palette, so they come out a little softer than pure CSS red and adjust for dark mode. Use a hex value if you need an exact shade.
Gotchas: the text is set in a math font, so it looks different from the sentence around it (\textsf{} gives sans-serif). Links and Markdown formatting inside the math do not work. If the text contains characters that clash with Markdown, use GitHub's alternative delimiter $`...`$. Use it sparingly: a README full of colored math is hard to read.

Method 3: Highlight With <mark>

If what you want is emphasis rather than a specific color, <mark> is the GitHub-safe option. It is on GitHub's HTML allowlist and renders with a yellow background in both themes, in the normal body font. The ==highlight== syntax some editors support is not GFM, and GitHub prints the equals signs.

Highlighted word

Markdown

Run the build <mark>before</mark> you tag the release.

Preview

Run the build before you tag the release.

In issues, pull requests, and discussions, GitHub also shows a color swatch next to a hex, RGB, or HSL value written in backticks, such as `#0969DA`. That previews a color value; it does not color your text.

Method 4: GitHub Alerts (Colored Callouts)

For a colored box rather than colored words, GitHub renders five blockquote types as alerts, each with its own color and icon. Put > [!TYPE] on the first line and the message on the following quoted lines. The full syntax is on the quotes and callouts guide.

NOTEGitHub

Markdown

> [!NOTE]
> Useful information that users should know, even when skimming content.

How it renders on GitHub

Note

Useful information that users should know, even when skimming content.

TIPGitHub

Markdown

> [!TIP]
> Helpful advice for doing things better or more easily.

How it renders on GitHub

Tip

Helpful advice for doing things better or more easily.

IMPORTANTGitHub

Markdown

> [!IMPORTANT]
> Key information users need to know to achieve their goal.

How it renders on GitHub

Important

Key information users need to know to achieve their goal.

WARNINGGitHub

Markdown

> [!WARNING]
> Urgent info that needs immediate user attention to avoid problems.

How it renders on GitHub

Warning

Urgent info that needs immediate user attention to avoid problems.

CAUTIONGitHub

Markdown

> [!CAUTION]
> Advises about risks or negative outcomes of certain actions.

How it renders on GitHub

Caution

Advises about risks or negative outcomes of certain actions.

Alerts cannot be nested inside other elements. Inside a list item or a <details> block, GitHub renders a plain blockquote with the [!WARNING] marker left visible.

Discord: ansi Code Blocks

Discord has no color syntax for normal text. What it has is the ansi code block, which renders terminal escape sequences: ESC[1;31m for bold red, ESC[0m to reset. ESC is the invisible character U+001B, so typing the letters \u001b does nothing. The block below shows the readable notation; its copy button gives you the real characters.

Paste into Discord as-is

Message

```ansi
\u001b[1;31mBold red text\u001b[0m
\u001b[0;32mGreen text\u001b[0m
```

How it looks in Discord

Bold red text

Green text

The Discord color text generator builds these blocks with a live preview and copies the escape characters for you. Discord changed the ansi palette in August 2026, and colors now vary by theme. Desktop and browser render them; the phone apps often show a plain monospace block, so don't rely on color alone. The full code table is in the Discord formatting guide.

The older trick: syntax highlighting

Before ansi, people picked a code block language whose highlighter happened to color a whole line. It is cruder, one color per line, but it needs no invisible characters.

Discord code block languages that color text, and what triggers each color
LanguageTriggerColor
```diffLine starts with -Red
```diffLine starts with +Green
```fixThe whole blockYellow
```iniText inside [brackets]Blue
```bashText inside "double quotes"Cyan

Notion, Obsidian, Pandoc, and Streamlit

A few tools added their own color syntax or UI. Where one exists, use it instead of HTML.

Native text color methods in Notion, Obsidian, Pandoc, Streamlit, and GitHub issues
ToolHowNotes
Notion/red or /red background, or the text color menuCmd/Ctrl+Shift+H re-applies the last color used. Notion does not render pasted HTML.
Obsidian<span style="color: red"> or ==highlight====text== is a yellow highlight only. CSS snippets let you define your own classes.
Pandoc / Quarto / R Markdown[red text]{style="color: red"}A bracketed span with attributes. Colors the HTML output; other formats need a filter.
Streamlit st.markdown:red[text] and :red-background[text]Built-in palette: red, orange, yellow, green, blue, violet, gray, rainbow, primary.
GitHub issues and PRs`#0969DA` in backticksShows a color swatch next to the code. A preview of a color value, not colored text.

More on each: Notion Markdown, Obsidian Markdown.

The Obsolete <font> Tag

<font color> was removed from HTML years ago, though browsers still render it. It is not a way around a sanitizer: GitHub, GitLab, and PyPI drop the tag entirely, and Notion does not render it. Anywhere it does work, <span style> works too, so there is no reason to use it in new content.

Renders in a browser-based preview; removed on GitHub

Markdown

<font color="red">This text uses the obsolete font tag.</font>

Preview

This text uses the obsolete font tag.

Common Mistakes

None of these produce an error. The text just comes out in the default color.

Broken

<span style="color: red">Important</span>

Fixed

$\color{red}{\text{Important}}$
On GitHub the span survives but its style attribute is stripped, so the text renders in the default color with no error. GitLab and PyPI do the same. Use LaTeX color, <mark>, or an alert there.

Broken

${\color{red}red text}$

Fixed

$\color{red}{\text{red text}}$
Math mode ignores spaces and sets letters in math italic, so this renders as redtext. Wrap words in \text{} to keep the spaces and an upright font.

Broken

<span style="color: red">text</span>

Fixed

<span style={{ color: "red" }}>text</span>
In MDX (Docusaurus, Next.js), HTML tags are JSX, and JSX wants style as an object. The string form throws instead of rendering.

Broken

[red](red) text

Fixed

<span style="color: red">text</span>
There is no [text](color) syntax. This is just a link to a page called red.

Platform Support

Color support comes down to two questions: does the renderer keep the style attribute, and does it render LaTeX math.

Best text color method by platform
PlatformBest method<span style>$\color{}$
GitHubLaTeX \color, <mark>, or alerts✗ Style stripped✓ Built in
GitLabLaTeX \color✗ Style stripped✓ Built in
PyPINone (no style, no math)✗ Style stripped✗ No math
VS Code preview<span style>✓ Works✓ Built in (KaTeX)
Obsidian<span style>✓ Works✓ Built in
NotionColor menu or /red✗ Not rendered✓ Inline equation
Jekyll, MkDocs, Eleventy, Astro (.md)<span style>✓ WorksNeeds a math plugin
Hugo<span style> after enabling raw HTML⚠ Off by defaultNeeds setup
MDX (Docusaurus, Next.js)style={{ color: 'red' }}⚠ Object syntax onlyNeeds a math plugin
Discord```ansi code block✗ No HTML✗ No math
SlackNone✗ No HTML✗ No math
RedditNone✗ No HTML✗ No math

Quick Reference

Markdown text color syntax quick reference
SyntaxResultUse it on
<span style="color: red">text</span>Red textObsidian, VS Code, Jekyll, MkDocs
$\color{green}{\text{text}}$Green text in a math fontGitHub, GitLab, Notion, Obsidian
<mark>text</mark>Yellow highlightGitHub and most HTML renderers
> [!WARNING]Yellow callout boxGitHub
```ansi + ESC[31mRed text in a code blockDiscord
```diff with - / +Red / green linesDiscord, GitHub
[text]{style="color: red"}Red textPandoc, Quarto, R Markdown
:red[text]Red textStreamlit

Frequently Asked Questions

How do I change text color in Markdown?

Standard Markdown has no color syntax, so you use the renderer's escape hatch. Where raw HTML with style attributes is allowed (Obsidian, VS Code preview, Jekyll, MkDocs, Eleventy, Astro), wrap the text in <span style="color: red">text</span>. GitHub, GitLab, and PyPI strip the style attribute, so on GitHub use LaTeX math instead: $\color{red}{\text{text}}$. Discord needs an ansi code block, and Slack and Reddit have no text color at all.

How do I add colored text in GitHub Markdown?

Use inline math with \color: $\color{red}{\text{red text}}$. It works in README files, issues, pull requests, discussions, and wikis. Keep words inside \text{} so spaces survive. For a highlight rather than a text color, <mark>text</mark> is kept by GitHub's sanitizer and renders with a yellow background. For callout boxes, use alerts such as > [!WARNING]. <span style> and <font color> do not work on GitHub.

Does the GitHub \color trick still work?

Yes, checked in October 2026. GitHub's MathJax now outputs native MathML, and \color becomes a mathcolor attribute. Hex values such as \color{#c026d3} render exactly. Seven named colors (red, blue, green, orange, yellow, purple, gray) are remapped to GitHub's theme palette, so \color{red} is a softer red that adapts to light and dark mode.

Why does my color span not render on GitHub?

GitHub sanitizes the HTML in Markdown and removes every style and class attribute. The <span> tag itself is kept, so your text appears, just in the default color. <font> is not on the allowlist at all and is removed entirely. There is no warning in either case.

How do I highlight text in Markdown?

Use the HTML <mark> tag: <mark>highlighted</mark>. GitHub keeps it and gives it a yellow background, and most HTML-allowing renderers do the same. ==highlight== is an extension that only some tools support (Obsidian, Typora with the setting on, Hugo with Goldmark extras enabled); GitHub prints the equals signs.

Can I change text color in GitLab Markdown?

Not with HTML. GitLab's sanitizer removes style attributes everywhere except text-align on table cells, and its docs state that Markdown does not support changing text color. GitLab renders LaTeX math, so $\color{red}{\text{text}}$ is the workaround. Separately, GitLab shows a color chip next to a hex, RGB, or HSL value written in backticks, which previews the color without coloring any text.

How do I color text in Discord?

Use an ansi code block. Open it with ```ansi and put an escape sequence such as ESC[1;31m before the text and ESC[0m after it, where ESC is the invisible U+001B character, so it has to be pasted rather than typed. Desktop and browser render the color; the phone apps often show plain monospace. The Discord color text generator builds the block and copies the real escape characters. The older ```diff trick still colors whole lines red or green.

How do I change text color in Notion?

Notion has its own color menu instead of Markdown syntax. Select text and pick a color, or type /red (or /red background) in a block. Cmd/Ctrl+Shift+H re-applies the last color you used. Pasted HTML like <span style> or <font color> is not rendered.

Does Obsidian support colored text?

Yes. Obsidian renders <span style="color: red">text</span>, and its math engine supports $\color{red}{\text{text}}$. Native ==highlight== syntax gives a single highlight color. For reusable colors, define a class in a CSS snippet and apply it with <span class="my-color">.

Why doesn't Markdown have a color syntax?

Markdown was designed to stay readable as plain text and to describe structure (headings, lists, emphasis), not presentation. Color is presentation, so it was left to HTML and CSS. CommonMark has never added it, which is why every method on this page is a workaround.