Accessibility Helpers
Faststrap now includes built-in accessibility primitives in faststrap.accessibility.
Why this exists
- Reduce repeated a11y boilerplate in every app.
- Make keyboard and screen-reader support default.
- Keep APIs simple and composable with existing FastHTML/Faststrap components.
When to use these helpers
- Any page with keyboard users in mind.
- Dynamic pages that update content after interactions.
- Dialog-like UI that must keep tab focus contained.
- Icon-only controls that need screen-reader labels.
Components
SkipLink
Use it near the top of your page so keyboard users can jump to main content immediately.
VisuallyHidden
Hides content visually while keeping it available to assistive technologies.
LiveRegion
Use for dynamic status updates that should be announced by screen readers.
FocusTrap
Wrap dialog-like content to constrain tab focus inside the container.
Practical pattern for dynamic updates
Div(
Button("Save", hx_post="/save", hx_target="#status"),
Div(id="status"),
LiveRegion(id="a11y-status"),
)
Use route responses to update both visible status and the live region where appropriate.
Recommended pattern
from faststrap import *
app = FastHTML()
add_bootstrap(app)
@app.get("/")
def home():
return Container(
SkipLink("#main-content"),
Div(
H1("Dashboard"),
id="main-content",
),
)
Accessibility notes
SkipLinkshould appear early in the DOM.LiveRegionshould be used for meaningful state changes (avoid noisy updates).FocusTrapis best for overlays, dialogs, and modal-like content.