Responsive and accessible pages
Make a page usable on any screen and for people who use a keyboard or a screen reader.
Most visitors use a phone. A responsive page adapts to the screen. An accessible page works for people with different abilities. Both come from the same habits.
Start mobile-first
Without the viewport meta tag, phones show a shrunken desktop page. Keep <meta name="viewport" content="width=device-width, initial-scale=1"> in the head. Write the simple one-column style first and add rules for wider screens.
.layout { display: grid; gap: 1rem; }
@media (min-width: 48rem) {
.layout { grid-template-columns: 2fr 1fr; }
}Accessibility basics
- Use semantic elements and one
<h1>. - Give every image meaningful
alttext, oralt=""if it is only decoration. - Keep a visible focus outline. Never write
outline: nonewithout a replacement. - Check contrast: normal text needs a ratio of at least 4.5 to 1 against its background (WCAG AA).
- Do not rely on color alone to show information.
- Make sure you can use the whole page with the Tab key.
CarefulDisabling zoom with user-scalable=no blocks people with low vision. Do not do it.
Test it
Open the browser developer tools, switch to the device toolbar and resize. Then try the Tab key, and run the Lighthouse accessibility audit.
Test yourself
Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.