Textualize/textual · error · StyleValueError

invalid value for visibility (received {new_value!r}, expect

Error message

invalid value for visibility (received {new_value!r}, expected {friendly_list(VALID_VISIBILITY)})

What it means

The visible setter accepts booleans or a valid CSS visibility keyword ('visible', 'hidden'); other values raise StyleValueError listing the accepted values.

Source

Thrown at src/textual/dom.py:963

        This may be set explicitly to override inherited values.
        The valid values include the valid values for the `visibility` rule and the booleans
        `True` or `False`, to set the widget to be visible or invisible, respectively.

        When a node is invisible, Textual will reserve space for it, but won't display anything.
        """
        own_value = self.styles.get_rule("visibility")
        if own_value is not None:
            return own_value != "hidden"
        return self.parent.visible if self.parent else True

    @visible.setter
    def visible(self, new_value: bool | str) -> None:
        if isinstance(new_value, bool):
            self.styles.visibility = "visible" if new_value else "hidden"
        elif new_value in VALID_VISIBILITY:
            self.styles.visibility = new_value
        else:
            raise StyleValueError(
                f"invalid value for visibility (received {new_value!r}, "
                f"expected {friendly_list(VALID_VISIBILITY)})"
            )

    @property
    def tree(self) -> Tree:
        """A Rich tree to display the DOM.

        Log this to visualize your app in the textual console.

        Example:
            ```python
            self.log(self.tree)
            ```

        Returns:
            A Tree renderable.
        """

View on GitHub (pinned to 06dbeef4bb)

Solutions

  1. Use True/False (mapped to 'visible'/'hidden') or one of the documented VALID_VISIBILITY strings
  2. Validate dynamic strings against VALID_VISIBILITY from textual.css.constants before assignment

Example fix

# before
widget.visible = 'collapse'  # StyleValueError

# after
widget.visible = False  # or 'hidden' / 'visible'
Defensive patterns

Strategy: type-guard

Validate before calling

from textual.css.constants import VALID_VISIBILITY

def set_visible(widget, value):
    if isinstance(value, bool) or value in VALID_VISIBILITY:
        widget.visible = value
    else:
        widget.visible = bool(value)

Type guard

from textual.css.constants import VALID_VISIBILITY
def is_valid_visibility(v) -> bool:
    return isinstance(v, bool) or (isinstance(v, str) and v in VALID_VISIBILITY)

Try / catch

try:
    widget.visible = value
except StyleValueError:
    widget.visible = True  # fallback to default visible

Prevention

When it happens

Trigger: Assigning widget.visible = 'collapse', 'initial', None, or any string not in VALID_VISIBILITY.

Common situations: Confusing CSS visibility keywords from web CSS (which has more values) with textual's subset; passing through unvalidated user/config-driven strings.

Related errors


AI-assisted analysis of Textualize/textual@06dbeef4bb (2026-08-27). Data as JSON: /api/errors/38abcdfd4cd484a4. Report an issue: GitHub.