Skip to content


The max-width style sets a maximum width for a widget.


max-width: <scalar>;

The max-width style accepts a <scalar> that defines an upper bound for the width of a widget. That is, the width of a widget is never allowed to exceed max-width.


The example below shows some placeholders that were defined to span horizontally from the left edge of the terminal to the right edge. Then, we set max-width individually on each placeholder.

MaxWidthApp max-width:  50h max-width: 999 max-width: 50% max-width: 30

from import App
from textual.containers import VerticalScroll
from textual.widgets import Placeholder

class MaxWidthApp(App):
    CSS_PATH = "max_width.tcss"

    def compose(self):
        yield VerticalScroll(
            Placeholder("max-width: 50h", id="p1"),
            Placeholder("max-width: 999", id="p2"),
            Placeholder("max-width: 50%", id="p3"),
            Placeholder("max-width: 30", id="p4"),

if __name__ == "__main__":
    app = MaxWidthApp()
Horizontal {
    height: 100%;
    width: 100%;

Placeholder {
    width: 100%;
    height: 1fr;

#p1 {
    max-width: 50h;

#p2 {
    max-width: 999;  /* (1)! */

#p3 {
    max-width: 50%;

#p4 {
    max-width: 30;
  1. This won't affect the placeholder because its width is less than the maximum width.


/* Set the maximum width to 10 rows */
max-width: 10;

/* Set the maximum width to 25% of the viewport width */
max-width: 25vw;


# Set the maximum width to 10 rows
widget.styles.max_width = 10

# Set the maximum width to 25% of the viewport width
widget.styles.max_width = "25vw"

See also

  • min-width to set a lower bound on the width of a widget.
  • width to set the width of a widget.