Rich supports a simple markup which you can use to insert color and styles virtually everywhere Rich would accept a string (e.g.
Console markup uses a syntax inspired by bbcode. If you write the style (see Styles) in square brackets, e.g.
[bold red], that style will apply until it is closed with a corresponding
Here’s a simple example:
from rich import print
print("[bold red]alert![/bold red] Something happened")
If you don’t close a style, it will apply until the end of the string. Which is sometimes convenient if you want to style a single line. For example:
print("[bold italic yellow on red blink]This text is impossible to read")
There is a shorthand for closing a style. If you omit the style name from the closing tag, Rich will close the last style. For example:
print("[bold red]Bold and red[/] not bold or red")
Console markup can output hyperlinks with the following syntax:
[link=URL]text[/link]. Here’s an example:
print("Visit my [link=https://www.willmcgugan.com]blog[/link]!")
If your terminal software supports hyperlinks, you will be able to click the word “blog” which will typically open a browser. If your terminal doesn’t support hyperlinks, you will see the text but it won’t be clickable.
Occasionally you may want to print something that Rich would interpret as markup. You can escape a tag by preceding it with backslash. Here’s an example:
>>> from rich import print
escape() will handle escaping of text for you.
By default, Rich will render console markup when you explicitly pass a string to
print() or implicitly when you embed a string in another renderable object such as
Console markup is convenient, but you may wish to disable it if the syntax clashes with the string you want to print. You can do this by setting
markup=False on the
print() method or on the