Skip to content

Text-style

The text-style rule enables a number of different ways of displaying text.

Text styles may be set in combination. For example bold underline or reverse underline strike.

Syntax

text-style: <TEXT STYLE> ...;

Values

Value Description
bold bold text
italic italic text
reverse reverse video text (foreground and background colors reversed)
underline underline text
strike strikethrough text

Example

Each of the three text panels has a different text style.

from textual.app import App
from textual.widgets import Static

TEXT = """I must not fear.
Fear is the mind-killer.
Fear is the little-death that brings total obliteration.
I will face my fear.
I will permit it to pass over me and through me.
And when it has gone past, I will turn the inner eye to see its path.
Where the fear has gone there will be nothing. Only I will remain."""


class TextStyleApp(App):
    def compose(self):
        yield Static(TEXT, id="static1")
        yield Static(TEXT, id="static2")
        yield Static(TEXT, id="static3")


app = TextStyleApp(css_path="text_style.css")
Screen {
    layout: horizontal;    
}
Static {
    width:1fr;        
}    
#static1 {
    background: red 30%;
    text-style: bold;
}
#static2 {
    background: green 30%;
    text-style: italic;
}
#static3 {
    background: blue 30%;
    text-style: reverse;
}

TextStyleApp I must not fear.I must not fear.I must not fear. Fear is the mind-killer.Fear is the mind-killer.Fear is the mind-killer. Fear is the little-death Fear is the little-death Fear is the little-death  that brings total that brings total that brings total  obliteration.obliteration.obliteration. I will face my fear.I will face my fear.I will face my fear. I will permit it to pass I will permit it to pass I will permit it to pass  over me and through me.over me and through me.over me and through me. And when it has gone past,And when it has gone past, And when it has gone past,  I will turn the inner eye I will turn the inner eye I will turn the inner eye  to see its path.to see its path.to see its path. Where the fear has gone Where the fear has gone Where the fear has gone  there will be nothing. there will be nothing. Onlythere will be nothing. Only Only I will remain.I will remain.I will remain.

CSS

text-style: italic;

Python

widget.styles.text_style = "italic"