Accessibility API
These helpers provide small, composable accessibility primitives. They do not replace semantic HTML, keyboard testing, or application-specific focus management; they make common patterns explicit in a FastHTML tree.
Choosing A Helper
| Helper | Use it for |
|---|---|
SkipLink |
A keyboard-first jump to the main content landmark. |
LiveRegion |
Announcing dynamic status or result changes to assistive technology. |
VisuallyHidden |
Screen-reader text that should not occupy visible layout space. |
FocusTrap |
Keeping keyboard focus inside a modal-like region while it is active. |
Example
from faststrap import FocusTrap, LiveRegion, SkipLink, VisuallyHidden
def accessible_layout(*content):
return (
SkipLink(target="#main-content"),
LiveRegion(id="status", politeness="polite"),
VisuallyHidden("Application navigation"),
FocusTrap(*content, autofocus_selector="#main-content"),
)
Use a real <main id="main-content"> landmark in the page and update a live region only for meaningful state changes. FocusTrap adds the focus-management hooks; the dialog's open/close lifecycle remains the application's responsibility.
API Reference
faststrap.accessibility.SkipLink(target='#main-content', text='Skip to main content', **kwargs)
Create a skip link for keyboard users.
Source code in src/faststrap/accessibility.py
faststrap.accessibility.LiveRegion(*children, politeness='polite', atomic=True, relevant='additions text', **kwargs)
Create an ARIA live region for dynamic status messages.
Source code in src/faststrap/accessibility.py
faststrap.accessibility.VisuallyHidden(*children, focusable=False, **kwargs)
Hide content visually while keeping it available to screen readers.
Source code in src/faststrap/accessibility.py
faststrap.accessibility.FocusTrap(*children, autofocus_selector=None, **kwargs)
Create a focus trap container for dialogs and overlays.