Skip to content

Accessibility ​

Some people use UNaIVERSE through a screen reader or the keyboard alone. Others need large text or reduced motion or read a phone in bright sun. The webapp around your view supports all of them. A view without the same support becomes the only part of the app these people cannot use. Most of the work is plain HTML used correctly. Seven points matter most in a view: (1) headings and labels, (2) real buttons, (3) focus, (4) new messages announced by the screen reader, (5) contrast in both themes, (6) reduced motion and (7) the keyboard.

A conversation everyone can use ​

The conversation below applies these points and works with the keyboard alone (Tab to the field, type the text and press Enter to send it).

jsx
import { useEffect, useRef, useState } from 'react';
import { useWorld } from './useWorld.js';

// A fake world to build with: no account, no network.
const desk = { name: 'Help desk', onMessage: (message) => `You said: ${message.text}` };

export default function App() {
	// While building: the fake world. In the webapp: useWorld()
	const { world, error } = useWorld({ fake: { world: desk } });
	const [text, setText] = useState('');
	const inputRef = useRef(null);
	const language = world?.webapp.language;

	// The language of the page tells a screen reader which voice to use.
	useEffect(() => {
		if (language) document.documentElement.lang = language;
	}, [language]);

	if (error) return <p>Could not connect ({error.code}).</p>;
	if (!world) return <p>Connecting…</p>;

	function send(event) {
		event.preventDefault();
		if (!text.trim()) return;
		world.send(text.trim());
		setText('');
		inputRef.current.focus(); // the focus stays where the person types
	}

	return (
		<>
			{/* One heading names the page for screen readers. */}
			<h1>{world.name}</h1>
			{/* A log: a screen reader reads each new message once, without interrupting.
			    With keys, React adds only the new items, and only those are read. */}
			<ol role="log" aria-live="polite" aria-label="Conversation">
				{world.messages.map((message) => (
					<li key={message.id}>{message.fromMe ? 'You' : message.from}: {message.text}</li>
				))}
			</ol>
			{/* A real form: Enter sends, and the field has a label a screen reader reads. */}
			<form onSubmit={send}>
				<label>
					Message <input ref={inputRef} value={text} onChange={(event) => setText(event.target.value)} />
				</label>
				<button>Send</button>
			</form>
		</>
	);
}
js
import { connectToHost } from '@unaiverse/gui-kit';

// A fake world to build with: no account, no network.
const desk = { name: 'Help desk', onMessage: (message) => `You said: ${message.text}` };

// While building: the fake world. In the webapp: const world = await connectToHost();
const world = await connectToHost({ fake: { world: desk } });

// One heading names the page for screen readers.
const title = document.createElement('h1');
// The messages go in a log, where a screen reader reads each new message once, without interrupting.
const log = document.createElement('ol');
log.setAttribute('role', 'log');
log.setAttribute('aria-live', 'polite');
log.setAttribute('aria-label', 'Conversation');
// A real form: Enter sends, and the field has a label a screen reader reads.
const form = document.createElement('form');
const label = document.createElement('label');
label.textContent = 'Message ';
const input = document.createElement('input');
label.append(input);
const button = document.createElement('button');
button.textContent = 'Send';
form.append(label, button);
document.body.append(title, log, form);

form.onsubmit = (event) => {
	event.preventDefault();
	const text = input.value.trim();
	if (!text) return;
	input.value = '';
	input.focus(); // the focus stays where the person types
	world.send(text);
};

// Add only the new messages: the log then reads only those.
let shown = 0;
world.subscribe((node) => {
	document.documentElement.lang = node.webapp.language;
	title.textContent = node.name;
	for (const message of node.messages.slice(shown)) {
		const item = document.createElement('li');
		item.textContent = `${message.fromMe ? 'You' : message.from}: ${message.text}`;
		log.append(item);
	}
	shown = node.messages.length;
});
Live, on a fake world
Open

Five parts of the example make it accessible:

  • an <h1> with the name of the world that a screen reader announces and lets the person jump to
  • the lang attribute of <html> whose value comes from node.webapp.language and selects the voice of the screen reader
  • an <ol> with role="log" and aria-live="polite" whose new items a screen reader reads once after it finishes its current announcement
  • a <form> whose field sits inside a <label> (Enter submits the form and a screen reader announces the field as "Message, edit text")
  • a call to input.focus() after sending that keeps the focus in the field for the next message.

Headings and the name of the page ​

Screen reader users move from heading to heading to skim a page. Give your view three things:

  • a <title> in the <head> of the page that names it in the browser and for screen readers
  • one <h1> for the main subject of the view followed by <h2> and <h3> for its parts in order and without skipped levels
  • <html lang="…"> with the value of world.webapp.language (The language of the webapp).

Labels ​

Every field needs a name that a screen reader can announce:

  • A visible <label> that wraps the field or points to it with for and id. A placeholder is not a label because it disappears as soon as the person types.
  • aria-label only where there is no visible text such as an icon button (<button aria-label="Send">➤</button>) or a field whose purpose is obvious from the layout.
  • Questions from the world carry their fields in message.form.fields. Label each field with its label or with its name when label is missing (Answer a question with a form).

Buttons instead of clickable boxes ​

Use <button> for every control that does something (sending, choosing an action, opening a panel) and <a href> for every control that leads to another address. A <div> with an onclick handler looks the same on screen but cannot be reached with the keyboard and is not announced as something to press.

When an action is not available because it is not the turn of the person or the rules do not offer it, show the reason next to the button instead of only disabling it. A disabled button gives no reason and a screen reader may skip it entirely.

Focus ​

Keep the focus visible and on the control where the person acts next:

  • Never remove the focus outline (outline: none) without drawing another one. Restyle it with :focus-visible and check it in both themes.
  • When a panel or dialog opens, move the focus into it (to its first field or to its heading with tabindex="-1"). When it closes, move the focus back to the button that opened it. Otherwise a keyboard user is left at the top of the page or inside an element that no longer exists.
  • A <dialog> opened with dialog.showModal() keeps the focus inside while it is open and closes on Escape.
  • After an action leave the focus on the control that the person uses next (the example calls input.focus() after sending).

Announcing new messages ​

A screen reader announces content that changes on its own only inside a live region. Mark as live regions the places where new content appears:

  • role="log" (which implies aria-live="polite") for a list that grows like a conversation. The screen reader reads the added items. Append new items at the end and leave the others in place since rebuilding the whole list can make it read everything again. In React key={message.id} keeps them in place.
  • role="status" for a short line that changes such as "Sent" or "Your turn". Keep the element mounted and change only its text.
  • Keep fast data out of live regions. A score or a clock that changes every second would be announced without end. Announce the moments that matter ("Your turn", "Ada won") in a status line and leave the changing number silent.

Colour and contrast in both themes ​

Every colour of the view has to pass in the light theme and in the dark theme:

  • Text needs a contrast ratio of at least 4.5:1 against its background. Large text (24 pixels or 19 pixels bold) and the borders of buttons and fields need at least 3:1. These are the thresholds of WCAG 2.2 (success criteria 1.4.3 and 1.4.11). The developer tools of the browser show the ratio of a text element when you inspect it.
  • Check both themes. A grey that reads well on white can vanish on black in the same way as a dark blue link in the dark theme.
  • Never use colour alone. A failed message in red also says "Not delivered" and the current player highlighted in green is also named.

Less motion ​

People who get dizzy from movement on screen ask their system for reduced motion. The view reads this preference from the browser with the media query prefers-reduced-motion because world.webapp does not carry it.

css
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
js
const wantsLessMotion = matchMedia('(prefers-reduced-motion: reduce)').matches;
list.lastElementChild?.scrollIntoView({ behavior: wantsLessMotion ? 'auto' : 'smooth' });

Whatever the preference, nothing in the view may flash more than three times per second.

The keyboard ​

A view must work from start to end with the keyboard alone:

  • Tab reaches every button, link and field in the order in which they appear on screen. A wrong order is fixed in the HTML and not with tabindex numbers.
  • Enter and Space press buttons, Enter submits a form and Escape closes what is open.
  • Arrow keys move inside a group that works as one control such as the cells of a game board or the options of a choice. Tab still moves the focus out of the group.
  • Nothing traps the focus except an open dialog that Escape closes.
  • Your own keyboard shortcuts leave alone the keys that the browser and screen readers use (single letters while typing, Tab and the arrows in a text field).

Pictures and canvases ​

  • Every picture has an alt. For a picture from the world, describe what it shows or use the text of the message it came with. A purely decorative picture takes alt="" and the screen reader skips it.
  • A canvas is invisible to a screen reader. When it shows something that matters (a game board, a chart), give the same content in text with a table of the board, a sentence with the numbers or an aria-label that sums it up and changes with it.

Test it ​

  • The keyboard alone for a whole round of your view.
  • A screen reader (VoiceOver on a Mac or an iPhone, TalkBack on Android, NVDA on Windows) while a few new messages arrive.
  • A zoom of 200% in the browser to check that the view still works and does not cut off any text.
  • Both themes with the pretended look.
  • An automatic check with Lighthouse in the developer tools of Chrome or with the axe extension. It finds missing labels and weak contrasts in seconds and does not replace the four checks above.

Next steps ​

The UNaIVERSE GUI kit, released under the Apache License 2.0. Copyright 2024-2026 UNaIVERSE S.r.l.