Text Cell#

You can write explanatory text.

  • By using tools covered in this section, you can compose well-organized texts.

  • To edit a text cell, double-click on it.

  • Click outside the text cell to exit the edit mode.

  • Text cells in Colab use Markdown language syntax.

  • When you start writing in a text cell, you will see another box on the right that shows the output.

  • Text cells do not have an arrow on the left for execution.

  • You do not need to memorize HTML code in this section; you can copy/paste it if needed.

Heading#

  • Start the line with a hashtag (#) followed by a space.

  • To make the header smaller, add more hashtags (#).

# Level-1 heading
## Level-2 heading
### Level-3 heading
#### Level-4 heading
##### Level-5 heading
###### Level-6 heading
  • The table of contents is located on the left side of Colab, marked by an icon displaying three rows of a dot and line.

  • All headings appear in the table of contents according to their level.

  • You can also use the tT icon on the text cell toolbar to create a text heading.

Center#

  • You can use the following HTML code to center text: <center> text </center>.

  • Output:

text

Bold#

  • Use ** (two asterisks) or __ (two underscores) on both sides of the text to apply bold formatting.

  • Alternatively, you can utilize the B icon on the text cell toolbar.

  • The output of How **are** you? is

    • How are you?

Italic#

  • Use * (one asterisk) or _ (one underscore) on both sides of the text to apply italic formatting.

  • Alternatively, you can utilize the I icon on the text cell toolbar.

  • The output of How *are* you? is

    • How are you?

Line Breaks#

  • Add 2 blank spaces or \ at the end of the line to start a new line.

Color#

  • You can use the following HTML code to change the color of text: <font color=red> text </font>.

  • Output: text

Size#

  • You can use the following HTML code to change the size of text:
    <font size=25> text </font>.

  • Output:

text

Size and Color#

  • You can use the following HTML code to change the color and size of text:
    <font size=25, color=red> text </font>.

  • Output:

text

List#

  • Use a dash (-), asterisk (*), or plus sign (+) followed by a space for an unordered (bullet) list.

  • Use numbers followed by a period (.) and a space for a numbered (ordered) list.

  • Indent to create a sublist.

The output of

- Africa
- Europe

is

  • Africa

  • Europe


The output of

- Africa
    1. Nigeria
    2. Kenya
- Europe
    1. Germany
    2. Italy
    3. Spain

is

  • Africa

    1. Nigeria

    2. Kenya

  • Europe

    1. Germany

    2. Italy

    3. Spain


The output of

- Africa
    1. Nigeria
    2. Kenya
- Europe
    1. Germany
        - Munich
        - Dortmund
        - Bonn
    2. Italy
    3. Spain

is

  • Africa

    1. Nigeria

    2. Kenya

  • Europe

    1. Germany

      • Munich

      • Dortmund

      • Bonn

    2. Italy

    3. Spain

  • Instead of dash (-) you can also use asterisk (*).

The output of

* Africa
* Europe

is

  • Africa

  • Europe


Highlight#

  • Enclose the text with one backtick on each side (`text`) to format it.

  • In a light Google Colab theme, the highlight might not be very visible.

  • For example, adding one backtick to each side of How are you? will display it as How are you?.

Yellow Highlight#

  • You can use the following HTML code to highlight the text in yellow: <mark>  text </mark>.

  • Output: text

Horizontal Line#

  • Use three asterisks (***) or underscores (___) on a new line.


  • In light mode, the horizontal line created by three asterisks (***) or underscores (___) might not be very noticeable.

Blockquote#

  • To create a blockquote, start a line with a greater than symbol (>).

  • Use additional greater than symbols for nested blockquotes.

The output of

> aaa  

is

aaa


The output of

> aaa \
> bbb

is

aaa
bbb


The output of

> aaa 
>> bbb

is

aaa

bbb


The output of

> aaa  
> bbb
>> ccc
>>>ddd

is

aaa
bbb

ccc

ddd

Table#

  • Use | (pipe) and - (dash) to create a table structure.

The output of

|Gender	| Age | State|  
| --- | --- | --- |  
| Male | 25 | NY |  
| Male | 35 | FL |.
| Female | 20 | CA | 

is

Gender

Age

State

Male

25

NY

Male

35

FL

Female

20

CA

Python code#

  • Use three backticks followed by the Python keyword to write Python code within a text cell, mimicking the appearance of a code cell.”

The output of

``` python
for i in range(6):
   if i>2:
     print(i)
  else:
     print(True)
```

is

for i in range(6):
  if i>2:
    print(i)
  else:
    print(True)

Mathematical Equations#

  • A text cell can execute Latex code.

  • If you are not familiar with Latex, feel free to skip this part.

  • The output of $ \int_1^5x^5\,dx$ is \(\int_1^5x^5\,dx\)

Add an Image#

  1. To import an image from your computer to a Colab notebook:

    • Double-click on the text cell to edit it.

    • Click on the image icon in the text cell’s toolbar.

    • Select the image you want to upload.

    • You might see a lengthy and odd-looking text, but you can ignore it.

    • Click outside the text cell to exit the edit mode.

  2. To import an image from an URL use the following markdown syntax: ![](URL)

  • The output of ![](https://www.python.org/static/community_logos/python-logo-master-v3-TM.png) is

  1. If you remove the ! from the code above, it will create a link to the website of the image instead of displaying the image directly in the notebook.

  • The output of [python logo](https://www.python.org/static/community_logos/python-powered-h-100x130.png) is python logo