Video hero
A short, silent clip behind the page title, for atmosphere only. Everything that matters is ordinary text on top, and the clip can always be stopped.
Direct, evidence-led, calmly delivered
Show code
---
import VideoToggle from '@somnia/core/components/VideoToggle.astro';
---
<section class="my-hero" data-page-hero>
<video data-bg-video autoplay muted loop playsinline poster="/about/poster.jpg" aria-hidden="true" tabindex="-1">
<source src="/about/clip.webm" type="video/webm" />
<source src="/about/clip.mp4" type="video/mp4" />
</video>
<div class="my-hero-scrim"></div>
<h1 class="sn-over-media">Direct, evidence-led, calmly delivered</h1>
<VideoToggle for="[data-bg-video]" />
</section> Full size, it is the top of About and of Headland Yachting's home page.
When to use it
- A page whose first job is a feeling: a place, a workshop, the sea.
- Real footage of the real thing exists. No actors, no stock.
Use something else when:
- The clip has something to say or show: a video player, which has sound, captions burnt in if it speaks, and controls.
- The page is one people come to for a task. A still, or a plain page hero, gets them there sooner.
How it works
- The poster still shows first, and is all that shows for anyone who asks for reduced motion or is saving data. The clip never starts for them.
- No audio track at all. The video is hidden from screen readers and can't take the focus; the heading and text over it are real, selectable text.
- A pause button (
VideoToggle) appears once the clip is playing. Its words say what a press will do: "Pause background video", then "Play background video". A clip that loops must have one. - Words that read on any frame. A dark scrim sits between the picture and the text, and the heading and opening line wear
.sn-over-media: a soft dark edge round each letter, for the frames where the picture is pale. - WebM and MP4 versions, under 4 MB, with a poster image. Not printed.
Speed and looping
A site can slow its hero clip (heroVideoRate in its config, e.g. 0.65 for a calmer feel; staging's Site style can try other speeds). fadeLoop() in lib/hero-rate.js loops a clip with a fade instead of a jump cut: it fades right out before the end, starts again while hidden and fades back in. It also keeps the hero from going blank: if the browser pauses or unloads the clip (a tab left in the background for a long time), the poster comes back and the clip starts again when the tab is looked at. A pause the visitor chose is left alone.
Phones
On an upright phone a landscape clip crops away most of the picture. Give phones their own portrait cut framed on the subject, or at least a focal point (object-position) so the subject stays in view, and keep the hero to about three-quarters of the screen so the next section shows. The pause button is its icon alone there, still named.
Do and don't
Do
- Choose a clip that is calm: slow, steady, no cuts
- Look at the words over its palest frame, not its poster
- Keep the pause button where it is on every page
Don't
- Put anything in the clip that people need to see
- Use sound
- Run a clip that flashes or moves fast behind text
Accessibility
What it does for you
- The clip is decoration: hidden from screen readers, never a stop for the keyboard, and it has no sound.
- A pause button appears once the clip plays. It is a plain button whose name says what a press will do: "Pause background video", then "Play background video".
- With reduced motion the clip never starts, the poster is the picture, and there is no button because there is nothing to stop.
- The heading and opening line are real text over a dark scrim, with a dark edge round each letter (
.sn-over-media) for the pale frames. - A pause the visitor chose is kept: the loop helper never restarts it.
What you need to do
- Look at the words over the clip’s palest frame. The scrim and the letter edge help; a clip that is white behind the heading for seconds at a time still needs a different cut or a stronger scrim.
- No flashing, and nothing fast behind text.
- Nothing in the clip that people need: it is not described to anyone.
- A poster, which is the whole hero for many visitors.
Keyboard
| Key | What it does |
|---|---|
| Tab | Reaches the pause button, after the hero’s own links and fields. |
| Enter or Space | Pauses the clip; again, plays it. The focus stays on the button. |
What a screen reader is told
- "Pause background video, button"; after a press, "Play background video".
- Nothing about the clip itself.
This is what the browser reports to assistive technology. What each screen reader then says varies, and has not been listened to yet.
WCAG 2.2
| Criterion | Level | How this meets it |
|---|---|---|
| 2.2.2 Pause, Stop, Hide | A | A clip that loops has a pause button. |
| 1.4.2 Audio Control | A | No audio track. |
| 2.3.3 Animation from Interactions | AAA | With reduced motion the clip doesn’t play. |
| 1.1.1 Non-text Content | A | The clip is decoration and is hidden. |
| 1.4.3 Contrast (Minimum) | AA | The words sit on a dark scrim, with a dark edge round the letters. |
| 2.5.8 Target Size (Minimum) | AA | The button is at least 32px high. |
| 4.1.2 Name, Role, Value | A | A button whose name changes with what it will do, and no second state. |
The criteria this component has a part in. A page that uses it still has to meet the rest.
Checked
| Check | How | Result |
|---|---|---|
| Automated (axe-core) | WCAG 2.0, 2.1 and 2.2 rules at A and AA, the page in light and in dark | Passed Nothing found, light or dark |
| Narrow screen | No sideways scrolling at 320px wide (WCAG 1.4.10) | Passed No sideways scrolling |
| Keyboard and what the browser reports | Real key presses on the live example, and the role, name and state given to assistive technology | Passed 11 of 11 checks pass |
| On paper | Somnia’s print check: no overlaps, stranded headings or controls on the page | Passed No faults on 6 sheets |
| Screen reader | Listened to by a person, in VoiceOver and NVDA | Not yet Not yet checked by a person |
The 11 checks made with the keyboard, on the example at the top of this page:
- Passed The clip is hidden from screen readers, can’t take the focus, and plays no sound
- Passed A pause button appears once the clip plays, named "Pause background video"
- Passed Tab reaches it; Enter pauses the clip and the button becomes "Play background video"; Enter again plays it. The focus stays on the button
- Passed Space works as Enter does
- Passed It is a plain button: its name changes, and it has no pressed state as well
- Passed On About, the clip that loops has the button, and it stops the clip
- Passed With reduced motion the clip doesn’t play and there is no button
- Passed The heading over the clip is real text, with a dark edge round its letters
- Passed Over a white frame, the scrim alone leaves the heading at least 3:1 and the line under it at least 4.5:1
- Passed The button is at least 24px high and shows a 2px ring with keyboard focus
- Passed On a phone the button is its icon alone, still named, and at least 24px square
Run by script on against Somnia DS 1.89.0, in Chromium with axe-core 4.14.0. How these checks work, and every component's results.
Not yet checked
- How it sounds in a screen reader (VoiceOver, NVDA, TalkBack) has not been checked by a person. The roles, names and states the browser reports are checked by script; what is actually spoken is not.
- Windows high contrast (forced colours) has not been looked at by a person.
- Contrast of words over moving pictures can’t be measured by a script: it changes with every frame. The scrim is measured where the opening line sits; the heading over a pale frame has been looked at, on a white test picture, not measured.
- The pause button comes after the hero’s content in the page, so a keyboard user passes that content first. WCAG asks only that it exists.
- Whether the clips in use flash has been judged by eye, not with a flash analysis tool.
Evidence
Where it's used
| Where | For |
|---|---|
| mediadreams.co.uk | The top of About: David at work, looping. |
| Headland Yachting | The home page, with a portrait cut for phones and a larger one for big screens, and its holding page. |
What we saw, and what changed
| When | What we saw | What changed |
|---|---|---|
| A hero clip played at its own speed and cut straight back to its start. | A speed setting, and a fade between loops (1.22.0). | |
| In a tab left in the background the hero went blank. | fadeLoop() brings the poster back whenever the clip isn’t showing; a pause the visitor chose stays (1.28.0). | |
| Media Dreams’ About clip looped for ever with no way to stop it. This page had never said a pause button was needed, and Headland’s hero had one of its own. | The button is Somnia’s, VideoToggle, on both (1.88.0). | |
| Headland’s button changed its name and its pressed state together: "Play background video, pressed". | The name alone changes (1.88.0). | |
| Headland’s white heading crossed a white sandbar in its clip and couldn’t be read there. | .sn-over-media: a dark edge round each letter, on both sites’ heroes (1.88.0). |
From building and using it on real sites, each entry taken from the changelog or the build's own notes. This is observation by the studio and its clients, not research sessions with users.
What it rests on
- Understanding WCAG 2.2: Pause, Stop, Hide: Anything that starts by itself, moves for more than five seconds and sits beside other content needs a way to pause, stop or hide it.
What we don't know yet
- How many visitors pause the clip is not counted.
- The hero round the button is still each site’s own code, so two layouts are kept in step by hand.
Status
Beta: the pause button and the text style are Somnia's; the hero round them is still each site's own (About here, VideoHero on Headland). It becomes one component when the two can share a layout.