Skip to content

SafeArea

Adds CSS env(safe-area-inset-*) padding or margin for phones with a display cutout or home indicator. It is CSS-only and safe on browsers that report zero insets.

from faststrap import SafeArea

SafeArea(
    "Mobile actions",
    edges="bottom",
    cls="bg-body border-top",
)
Parameter Type Default Description
*children Any () Wrapped content.
edges str "all" all, top, right, bottom, left, vertical, or horizontal.
mode str "padding" Apply the inset as padding or margin.
**kwargs Any HTML, HTMX, and class attributes.

Use edges="bottom" around fixed bottom navigation and action bars; use edges="top" for full-screen mobile headers.

faststrap.components.layout.safe_area.SafeArea(*children, edges='all', mode='padding', **kwargs)

Wrap content with CSS safe-area inset padding or margin.

Source code in src/faststrap/components/layout/safe_area.py
@register(category="layout")
@beta
def SafeArea(
    *children: Any,
    edges: SafeAreaEdges = "all",
    mode: SafeAreaMode = "padding",
    **kwargs: Any,
) -> Div:
    """Wrap content with CSS safe-area inset padding or margin."""
    if edges not in {"all", "top", "right", "bottom", "left", "vertical", "horizontal"}:
        raise ValueError("edges must be a supported safe-area edge group")
    if mode not in {"padding", "margin"}:
        raise ValueError("mode must be 'padding' or 'margin'")

    user_cls = kwargs.pop("cls", "")
    attrs = {
        "cls": merge_classes(
            "faststrap-safe-area",
            f"safe-area-{mode}-{edges}",
            user_cls,
        )
    }
    attrs.update(convert_attrs(kwargs))
    return Div(*children, **attrs)