How to embed HTML into IPython output?

This seems to work for me:

from IPython.core.display import display, HTML
display(HTML('<h1>Hello, world!</h1>'))

The trick is to wrap it in display as well.

Source: http://python.6.x6.nabble.com/Printing-HTML-within-IPython-Notebook-IPython-specific-prettyprint-tp5016624p5016631.html

Edit:

from IPython.display import display, HTML

In order to avoid:

DeprecationWarning: Importing display from IPython.core.display is 
deprecated since IPython 7.14, please import from IPython display

Leave a Comment