How to Color and Style the Console Output

5.3 version
Symfony 5.3 is backed by JoliCode.

How to Color and Style the Console Output

By using colors in the command output, you can distinguish different types of output (e.g. important messages, titles, comments, etc.).


By default, the Windows command console doesn’t support output coloring. The Console component disables output coloring for Windows systems, but if your commands invoke other scripts which emit color sequences, they will be wrongly displayed as raw escape characters. Install the Cmder, ConEmu, ANSICON, Mintty (used by default in GitBash and Cygwin) or Hyper free applications to add coloring support to your Windows command console.

Using Color Styles

Whenever you output text, you can surround the text with tags to color its output. For example:

// green text

// yellow text

// black text on a cyan background

// white text on a red background

The closing tag can be replaced by </>, which revokes all formatting options established by the last opened tag.

It is possible to define your own styles using the Symfony\Component\Console\Formatter\OutputFormatterStyle class:

use Symfony\Component\Console\Formatter\OutputFormatterStyle;

// ...
$outputStyle = new OutputFormatterStyle('red', '#ff0', ['bold', 'blink']);
$output->getFormatter()->setStyle('fire', $outputStyle);


Any hex color is supported for foreground and background colors. Besides that, these named colors are supported: black, red, green, yellow, blue, magenta, cyan, white, gray, bright-red, bright-green, bright-yellow, bright-blue, bright-magenta, bright-cyan and bright-white.

New in version 5.2: True (hex) color support was introduced in Symfony 5.2

New in version 5.3: Support for bright colors was introduced in Symfony 5.3.


If the terminal doesn’t support true colors, the nearest named color is used. E.g. #c0392b is degraded to red or #f1c40f is degraded to yellow.

And available options are: bold, underscore, blink, reverse (enables the “reverse video” mode where the background and foreground colors are swapped) and conceal (sets the foreground color to transparent, making the typed text invisible - although it can be selected and copied; this option is commonly used when asking the user to type sensitive information).

You can also set these colors and options directly inside the tag name:

// green text

// red text

// black text on a cyan background

// bold text on a yellow background

// bold text with underscore


If you need to render a tag literally, escape it with a backslash: \<info> or use the escape() method to escape all the tags included in the given string.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.