Question

I'm only looking to format a specific string within a cell. I change that cell's format to "Markdown" but I'm not sure how to change text color of a single word.

I don't want to change the look of the whole notebook (via a CSS file).

Was it helpful?

Solution

You can simply use raw html tags like

foo <font color='red'>bar</font> foo

Be aware that this will not survive a conversion of the notebook to latex.

As there are some complaints about the deprecation of the proposed solution. They are totally valid and Scott has already answered the question with a more recent, i.e. CSS based approach. Nevertheless, this answer shows some general approach to use html tags within IPython to style markdown cell content beyond the available pure markdown capabilities.

OTHER TIPS

Similarly to Jakob's answer, you can use HTML tags. Just a note that the color attribute of font (<font color=...>) is deprecated in HTML5. The following syntax would be HTML5-compliant:

This <span style="color:red">word</span> is not black.

Same caution that Jakob made probably still applies:

Be aware that this will not survive a conversion of the notebook to latex.

An alternative way to do that, is to enter a LaTeX environment within the notebook and change color from there (which is great if you are more fluent in LaTeX than in HTML). Example:

$\color{red}{\text{ciao}}$

would display ciao in red.

For example, if you want to make the color of "text" green, just type:

<font color='green'>text</font>

The text color can be changed using,

<span style='color:green'> message/text </span>
<span style='color:blue '> your message/text </span>

So here it is a perfect html css style entry inside a notebook ipynb file.

Of course you can choose your favourite color here and then your text.

If none of the above suggestions works for you, try using the style attribute.

**Notes**
<p style="color:red;">ERROR: Setting focus didn't work for me when I tried from jupyter. However it worked well when I ran it from the terminal</p>

This gives me the following result

enter image description here

I have tested the ideas that I found in these answers in google colabs.

<span style='color:red'>green</span> 
$\color{green}{\text{blue}}$ 
<font color='red'>orange</font>

Of these the 2nd (LaTeX $…$, and html font) versions work. The style version does not work.

Note: the html font element is deprecated. Therefore I am using the LaTeX version.

<p style="font-family: Arial; font-size:1.4em;color:gold;"> Golden </p>

or

Text <span style="font-family: Arial; font-size:1.4em;color:gold;"> Golden </p> Text

This is a very simple and effective trick for google colab. Use the (empty) link syntax of the markdown.

[your_message]()

Then you'll get the blue text (underline).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top