How to change the color of specific Text in Markdown

avatar
Borislav Hadzhiev

Last updated: Apr 5, 2024
4 min

banner

# Table of Contents

  1. How to change the color of specific Text in Markdown
  2. Apply a specific color to all text in a Markdown document
  3. Change the color of text in markdown via custom tags
  4. Using emojis to add colors in Markdown
  5. Using LATEX to color text in markdown

# How to change the color of specific Text in Markdown

To change the color of specific text in markdown:

  1. Wrap the text in a span tag.
  2. Set the style attribute on the span element.
  3. Set the color CSS property to your preferred color.
README.md
A very <span style='color: red;'>long</span> sentence.

change color of text in markdown

There isn't a native way to change the color of text in markdown.

However, you can use HTML tags.

We wrapped the text in a span element and set the style attribute on the element.

README.md
A very <span style='color: red;'>long</span> sentence.

The last step is to set the color CSS property to your preferred color.

This approach also enables you to change the color of the text in Jupyter Notebook markdown.

change text color in jupyter notebook

Make sure to select markdown from the dropdown menu as shown in the screenshot.

Note that GitHub strips the HTML tags and the style attribute, so this wouldn't work in GitHub markdown.

However, there are some other options that are covered below.

# Apply a specific color to all text in a Markdown document

If you need to apply a specific color to all text in the document, add a style tag at the top of your markdown file.

README.md
<style> body { color: red; } </style> A very long sentence. bobbyhadz.com

apply text color to all text on page

# Change the color of text in markdown via custom tags

You can also define custom tags in a style element to change the color of specific text.

README.md
<style> blue { color: lightblue; } red { color: red; } green { color: lightgreen; } </style> A <blue>very</blue> long <red>sentence</red>. <green>bobbyhadz</green>.com

change color of specific text using markdown

You can define as many custom tags in your style element as necessary.

Just make sure that the names of your custom tags don't clash with the names of built-in tags, e.g. b, i, div, etc.

# Using emojis to add colors in Markdown

The previous approaches don't work in GitHub markdown because GitHub automatically strips HTML tags and style attributes for security reasons.

However, you could also use emojis to draw attention to specific text.

Here are some examples.

README.md
โœ…๏ธ **Check**, ๐Ÿ’ก **Idea**, ๐Ÿ“ **Note**, โš ๏ธ **Warning**, โ—๏ธ**Important**, ๐Ÿ“Œ **Important**, ๐Ÿšจ **Warning**, โ›”๏ธ **Error**, โŒ **Error**

color text using emojis

And here is a screenshot of how this looks in GitHub markdown.

color text using emojis in github markdown

This approach also works in Jupyter Notebook markdown.

color text in jupyter notebook using emojis

There are many operating system-specific applications and web pages that enable you to filter through and copy emojis.

For example, this GitHub gist and this one have quite a few.

There are also many GitHub-specific emojis.

You can also view them in this GitHub repo.

Here are some examples of emojis that will only get rendered in GitHub markdown.

README.md
:heavy_check_mark: **Check**, :bulb: **Idea**, :pencil: **Note**, :warning: **Warning**, :exclamation: **Important**, :pushpin: **Important**, :rotating_light: **Warning**, :no_entry: **Error**, :x: **Error**

add color around text with github specific emojis

The example above wouldn't work in vanilla markdown or Jupyter Notebook markdown and should only be used in GitHub markdown.

I've also written a detailed article on How to create an Alert/Admonition Box in GitHub Markdown.

You can also use red, colored circles instead of emojis.

README.md
๐Ÿ”ด **Red** ๐Ÿ”ด, ๐Ÿ”ต **Blue** ๐Ÿ”ต, โšช๏ธ **White** โšช๏ธ, <br> โšซ **Black** โšซ, ๐ŸŸ  **Orange** ๐ŸŸ , ๐ŸŸก **Yellow** ๐ŸŸก, <br> ๐ŸŸข **Green** ๐ŸŸข, ๐ŸŸฃ **Purple** ๐ŸŸฃ

use red colored circles to color text

This approach also works in GitHub markdown.

using colored circles in github markdown

And in Jupyter Notebook markdown.

using colored circles in jupyter notebook markdown

If you need to add a new line in markdown, check out the following article.

# Using LATEX to color text in markdown

Depending on where you need to render your markdown, you might also be able to use LATEX to add colors to the text.

For example, the following works in GitHub markdown.

README.md
${\color{red}Some \space text \space here}$ <br> ${\color{green}Some \space text \space here}$ <br> ${\color{lightgreen}Light \space Green}$ <br>

github markdown color text using latex

You can specify the color between the curly braces {} as shown in the code sample.

However, notice that you must use an escaped \space sequence, instead of pressing the space button, to add whitespace.

The style above works in GitHub markdown.

If you need to apply colors to text in vanilla markdown or Jupyter Notebook markdown, try the following syntax instead.

README.md
$\color{red}{Some \space text \space here}$ <br> $\color{green}{Some \space text \space here}$ <br> $\color{lightblue}{Some \space text \space here}$ <br>

change color of text using latex in markdown

I've also written articles on:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev