The Markup class allows you to output rich text to the console.


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 [/].

AnsiConsole.Render(new Markup("[bold yellow]Hello[/] [red]World![/]"));

The Markup class implements IRenderable which means that you can use this in tables, grids, and panels. Most classes that support rendering of IRenderable also have overloads for rendering rich text.

var table = new Table();
table.AddColumn(new TableColumn(new Markup("[yellow]Foo[/]")));
table.AddColumn(new TableColumn("[blue]Bar[/]"));

Convenience methods

There is also convenience methods on AnsiConsole that can be used to write markup text to the console without instantiating a new Markup instance.

AnsiConsole.Markup("[underline green]Hello[/] ");

Escaping format characters

To output a [ you use [[, and to output a ] you use ]].

AnsiConsole.Markup("[[Hello]] "); // [Hello]
AnsiConsole.Markup("[red][[World]][/]"); // [World]

You can also use the EscapeMarkup extension method.

AnsiConsole.Markup("[red]{0}[/]", "Hello [World]".EscapeMarkup());

You can also use the Markup.Escape method.

AnsiConsole.Markup("[red]{0}[/]", Markup.Escape("Hello [World]"));

Setting background color

You can set the background color in markup by prefixing the color with on.

AnsiConsole.Markup("[bold yellow on blue]Hello[/]");
AnsiConsole.Markup("[default on blue]World[/]");

Rendering emojis

To output an emoji as part of markup, you can use emoji shortcodes.

AnsiConsole.Markup("Hello :globe_showing_europe_africa:!");

For a list of emoji, see the Emojis appendix section.


In the examples above, all colors was referenced by their name, but you can also use the hex or rgb representation for colors in markdown.

AnsiConsole.Markup("[red]Foo[/] ");
AnsiConsole.Markup("[#ff0000]Bar[/] ");
AnsiConsole.Markup("[rgb(255,0,0)]Baz[/] ");

For a list of colors, see the Colors appendix section.


For a list of styles, see the Styles appendix section.