Files
textual/questions/align-center-middle.question.md

750 B

title, alt_titles
title alt_titles
How do I center a widget in a screen?
centre a widget
center a control
centre a control

To center a widget within a container use align. But remember that align works on the children of a container, it isn't something you use on the child you want centered.

For example, here's an app that shows a Button in the middle of a Screen:

from textual.app import App, ComposeResult
from textual.widgets import Button

class ButtonApp(App):

    CSS = """
    Screen {
        align: center middle;
    }
    """

    def compose(self) -> ComposeResult:
        yield Button("PUSH ME!")

if __name__ == "__main__":
    ButtonApp().run()