How to add a new line in a Jupyter Notebook markdown cell

avatar
Borislav Hadzhiev

Last updated: Apr 10, 2024
3 min

banner

# How to add a new line in a Jupyter Notebook markdown cell

Use the <br> tag to add a new line in a Jupyter Notebook markdown cell.

The <br> tag stands for "line break" and is used to produce a line break in the text.

example.md
bobby <br> hadz <br> com

add new line in jupyter markdown using br tag

Make sure Markdown is selected from the dropdown as shown in the screenshot.

You can run the code by clicking on the > Run button or by pressing Ctrl + Enter.

The following output is produced.

added new line in jupyter notebook markdown cell

Markdown is a markup language that is a superset of HTML, so we can use HTML elements such as br directly in our markdown code.

The <br> element produces a line break in the text.

Note that this approach doesn't work if you need to export the notebook to a pdf because <br> elements get treated as spaces.

# Using two spaces to add a new line in a Jupyter Notebook markdown cell

You can also use two consecutive spaces to add a new line in a Jupyter Notebook markdown cell.

Note that 1 space won't work, you have to add 2 spaces for them to be treated as a newline character.
example.md
bobby␣␣ hadz␣␣ com

Where represents a space.

You simply press the Space key twice at the end of each line and then hit Enter.

using two spaces to add a new line

A <br> tag can be inserted by ending a line with two or more spaces.

Here is the output of running the code in the cell.

output of using two spaces to add new line

# Using a backslash to add a new line in a Jupyter Notebook markdown cell

You can also use a backslash \ character to achieve the same result.

example.md
bobby \ hadz \ com

add new line using backslash

Simply add a backslash \ character at the end of each line where you want to insert a newline character.

I'll click on the Run > button to run the code in the cell.

Running the code produces the following output.

output of adding new lines with backslash

# You can press Enter twice to start a new paragraph

You can also press the Enter key twice to start a new paragraph.

example.md
bobby hadz com

add new line by pressing enter twice

Simply press the Enter key twice at the end of each line.

Here is the output that is produced by running the code in the cell.

output from pressing enter key twice

If you encounter any issues when running the code in the cells, try restarting the kernel.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

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.