Styling enhances user experience by adding colors, emphasis, and other visual aids. In ratatui,
the primary tool for this is the ratatui::style::Style struct.
ratatui::style::Style provides a set of methods to apply styling attributes to your text. These
styles can then be applied to various text structures like Text, Span, and Line (as well as
other non text structures).
Common styling attributes include:
Foreground and Background Colors (fg and bg)
Modifiers (like bold, italic, and underline)
Basic Color Styling
Setting the foreground (text color) and background:
Using Modifiers
Making text bold or italic:
You can also combine multiple modifiers:
Styling within a Line
You can mix and match different styled spans within a single line:
This is what it would look like if you rendered a Paragraph with different styles for each line:
Here’s the HTML representation of the above styling:
Hello, Ratatui!
This is bold
This is italic
This is bold and italic
This is mixedstyling
!
You can read more about the
Color enum and
Modifier in the reference
documentation online.