Search code examples
githubmarkdowngithub-flavored-markdown

Applying color in a Markdown file on GitHub


Can I, in some way, color Markdown content?

I'm putting this in a gist on GitHub and was wondering if I could in some way color specific parts in my .md file. I’m pretty sure the .md file does support some HTML, but I’m not fully certain. If it does support coloring with HTML, how would that be done? If so, can I also change the font?


Solution

  • In general you can include arbitrary HTML in your Markdown, but there's no guarantee that the renderer will honour it all. For example:

    Hi here is some text <span style="color: red">this is red</span>.
    

    renders on SO to:

    Hi here is some text this is red.

    Although all of the text is included, the span gets stripped out entirely:

    <p>Hi here is some text this is red.</p>
    

    Similarly, it looks like GitHub strips the styling out (it's "sanitized, aggressively" - it leaves the span, at least, but removes the style attribute, see Gist):

    <p>Hi here is some text <span>this is red</span>.</p>