Accessibility and i18n
How Media Boxes works with keyboards, screen readers and reduced motion, and how to translate every label, set number formats and run right-to-left grids.
Accessibility is part of the engine, not an add-on. Controls are real buttons and links, focus is always visible, hover effects also work on keyboard focus, and every piece of text the engine writes can be translated.
Keyboard and screen readers #
In the grid #
- Items are in the page as normal content, in source order. The thumbnail link is a real
<a>, so Tab reaches it and Enter opens it. - Filter pills are
<button>elements witharia-pressed. Each filter group hasrole="group"and a name from itslabel. Drop-down filters are real<select>elements with a hidden label. - The search box is an
input type="search"with anaria-label(fromsearch.placeholder) and a clear button. Esc clears it. - Pagination buttons have labels such as "Page 3", and the current one has
aria-current="page". - Hover effects also run on
:focus-visible, so a keyboard user sees the same caption a mouse user does. On touch devices thehoverskin shows its caption all the time. - Items filtered out are hidden with
display: noneand cannot be focused. Items that are not loaded yet are hidden the same way. - A hidden live region announces "Showing 12 of 40" after every filter, search or load, or "Nothing matches your filters." when the result is empty.
- Each item link that opens the lightbox gets an
aria-labelsuch as "Open White stair" built fromi18n.openand the item title.
In the lightbox #
- It is a native
<dialog>opened withshowModal(). Focus moves into it, Tab stays inside it, Esc closes it, and focus returns to the thumbnail that opened it. - Every button has an accessible name from
i18n(Close, Next, Previous, Zoom in, and so on). Custom toolbar buttons use theirlabel. - The counter is a polite live region, so a screen reader hears "3 / 12" when the slide changes.
- Keyboard: arrows, Home, End,
+,-,0, Space andf, as listed in Lightbox. - Touch targets are at least 40px.
- Page scroll is locked without a layout shift.
Colour and contrast #
If you change colours, check the contrast yourself: --mb-accent-contrast on top of --mb-accent, --mb-text-muted on your surface colours, and --mb-focus against your page, which must stay clearly visible. See Theming.
Reduced motion #
When a visitor asks their system for reduced motion (prefers-reduced-motion: reduce):
- Items move to their new place with no transition, there is no stagger, and the entry animation is a plain fade.
- The hover effects become near instant, and the
tilteffect is switched off. - In the lightbox, slides change without travelling, opening and closing are a fade, and the spring motion and inertia are not used.
You do not have to do anything for this to work.
Translating the interface #
All text the engine writes comes from the i18n option. Set only the keys you want to change. The rest keep their English defaults.
<media-boxes id="galerie" filter="category" search>
<script type="application/json" data-mb-options>
{
"i18n": {
"all": "Alle",
"search": "Suchen…",
"clearSearch": "Suche löschen",
"loadMore": "Mehr laden",
"noResults": "Keine Treffer.",
"showing": "{count} von {total} angezeigt",
"close": "Schließen",
"next": "Weiter",
"previous": "Zurück",
"counter": "{current} von {total}",
"open": "{title} öffnen"
}
}
</script>
<!-- items -->
</media-boxes>grid.options = { i18n: { loadMore: 'Voir plus', close: 'Fermer' } };These are all the keys and their defaults:
| Key | Default text |
|---|---|
all | 'All' |
search | 'Search…' |
clearSearch | 'Clear search' |
sortBy | 'Sort by' |
ascending | 'Ascending' |
descending | 'Descending' |
loadMore | 'Load more' |
loading | 'Loading…' |
noResults | 'Nothing matches your filters.' |
showing | 'Showing {count} of {total}' |
page | 'Page {n}' |
pagination | 'Pagination' |
close | 'Close' |
next | 'Next' |
previous | 'Previous' |
zoomIn | 'Zoom in' |
zoomOut | 'Zoom out' |
play | 'Start slideshow' |
pause | 'Pause slideshow' |
fullscreen | 'Fullscreen' |
exitFullscreen | 'Exit fullscreen' |
download | 'Download' |
share | 'Share' |
thumbnails | 'Thumbnails' |
counter | '{current} / {total}' |
open | 'Open {title}' |
copied | 'Link copied' |
error | 'This could not be loaded.' |
lightbox | 'Lightbox' |
gallery | '{n} photos' |
playVideo | 'Play {title}' |
stopVideo | 'Stop video' |
Some strings contain placeholders in braces, which are replaced at run time: {count} and {total} in showing, {n} in page, {current} and {total} in counter, {title} in open and playVideo, and {n} in gallery. Keep them in your translation.
The pagination navigation also reads an optional pagination key (default "Pagination") for its landmark name. It is not in the defaults list, so add it yourself if you translate the page.
Also translate what you write yourself: the group label and all text of each filter, the sort option labels, the search placeholder, and the text of your own toolbar buttons.
Numbers, prices and dates #
For items built from data, the locale and currency options set the number and price format:
grid.options = { locale: 'de-DE', currency: 'EUR' }; // 1.299 €Dates are shown with the browser's own language. If you need a fixed format, write the date yourself into meta.
Set lang on <html> (and on a grid if its language differs) so screen readers pronounce the content correctly.
Right-to-left languages #
Set dir="rtl" on the page or on the grid. The grid reads the computed direction, so items start at the right, the filters and search box flip, and the pagination arrows point the right way.
<html lang="ar" dir="rtl">The lightbox takes its direction from the <html> element, so for an Arabic or Hebrew lightbox set dir="rtl" on <html> and not only on the grid. In an RTL lightbox the arrow keys follow the reading direction: the left arrow goes to the next slide, as the slides run right to left. If you remap keys to next and prev, they swap in the same way. See the RTL demo.