Frontend development · Intermediate · 20 min
Build a time slot picker with radio buttons
By Padding · Updated 18 Nov 2026
Modern browsers · HTML Living Standard and CSS Selectors Level 4 · checked in Chromium 159
You will build the Larkfield Clinic time slot picker from native radio buttons styled as chips, with a tick on the chosen time, taken slots that are announced and skipped, morning and afternoon groups, and a browser test that books 10:30 with the keyboard.
On this page
A time slot picker looks like a row of buttons, so it is often built from divs with click handlers. That version then needs JavaScript for selection, extra code for arrow keys, ARIA roles so screen readers know what it is, and still breaks in ways nobody tested. Choosing one time from a list is exactly what a group of radio buttons does. The browser already gives them a group name, a single selection, arrow-key movement, a disabled state and form submission. Your job is only to change how they look.
This tutorial builds the Pick a time screen of the Larkfield Clinic booking app, a fictional community clinic used across the design track. The patient has chosen a Nurse appointment (15 minutes) and is looking at Tuesday 9 December. There are nine times in two groups: Morning (09:00, 09:20, 09:40, 10:30, 11:00) and Afternoon (14:00, 14:40, 15:20, 16:00). Two of them, 09:40 and 14:40, are already taken. The patient wants 10:30.
The colours come from the Larkfield high-fidelity design: accent #0F5E5A for the selected slot, border #7D8592 for unselected slot edges, text #1B1F24, text-muted #5A6270 and the canvas #F6F7F8 background. The finished picker uses no JavaScript at all, which also keeps the page small and quick on a low-end Android phone on prepaid data.
Step 1 · Write the markup
Make a demo folder and write the page. Each time is an <input type="radio"> inside its own <label>, so clicking anywhere on the label selects the time. All nine radios share name="slot", which is what makes them one group: choosing one clears the others, wherever they sit on the page.
mkdir -p ~/slot-picker-demo
cd ~/slot-picker-demo
cat > index.html <<'HTML'
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pick a time · Larkfield Clinic</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<main>
<h1>Pick a time</h1>
<p class="service">Nurse appointment · 15 min</p>
<form method="get">
<fieldset class="day">
<legend>Tue 9 Dec</legend>
<fieldset class="period">
<legend>Morning</legend>
<div class="slots">
<label class="slot"><input type="radio" name="slot" value="09:00" required><span class="tick" aria-hidden="true"></span>09:00</label>
<label class="slot"><input type="radio" name="slot" value="09:20"><span class="tick" aria-hidden="true"></span>09:20</label>
<label class="slot"><input type="radio" name="slot" value="09:40" disabled><span class="tick" aria-hidden="true"></span>09:40 <span class="taken">Taken</span></label>
<label class="slot"><input type="radio" name="slot" value="10:30"><span class="tick" aria-hidden="true"></span>10:30</label>
<label class="slot"><input type="radio" name="slot" value="11:00"><span class="tick" aria-hidden="true"></span>11:00</label>
</div>
</fieldset>
<fieldset class="period">
<legend>Afternoon</legend>
<div class="slots">
<label class="slot"><input type="radio" name="slot" value="14:00"><span class="tick" aria-hidden="true"></span>14:00</label>
<label class="slot"><input type="radio" name="slot" value="14:40" disabled><span class="tick" aria-hidden="true"></span>14:40 <span class="taken">Taken</span></label>
<label class="slot"><input type="radio" name="slot" value="15:20"><span class="tick" aria-hidden="true"></span>15:20</label>
<label class="slot"><input type="radio" name="slot" value="16:00"><span class="tick" aria-hidden="true"></span>16:00</label>
</div>
</fieldset>
</fieldset>
<p class="fallback">Can't see a time that works? Call 01234 567 890</p>
<button type="submit">Continue</button>
</form>
</main>
</body>
</html>
HTML
touch style.cssThree details in that markup do the accessibility work:
- Nested fieldsets. The outer
<fieldset>with the legendTue 9 Decnames the whole choice. The inner ones,MorningandAfternoon, name each half. A screen reader entering 10:30 reads the group names along with it, so the patient hears which day and which part of it they are in. Grouping does not split the radio group, because the group comes from the sharedname, not from the fieldset. - The word "Taken" is inside the label. A taken slot keeps its time and adds a visible word. The label text becomes the radio's accessible name, so assistive technology reads "09:40 Taken" along with a disabled or unavailable state, depending on the screen reader.
disabledon the taken radios. The browser will not let anyone choose them, by mouse, keyboard or form submission.
The empty .tick spans are placeholders for the tick you draw in CSS later. aria-hidden="true" keeps them out of what screen readers read.
Check it worked
Open index.html in your browser (open index.html on macOS, xdg-open index.html on Linux, or drag the file into a window). You see a heading, the service line, a box with the legend Tue 9 Dec and two smaller boxes inside it labelled Morning and Afternoon, each holding small round radio buttons with times beside them. 09:40 and 14:40 are greyed out and read Taken. Click 10:30, then click 14:00: the first selection clears when you make the second.
Step 2 · Try the keyboard before any styling
Before you change how anything looks, learn what the browser already does, because the styling must keep all of it. Reload the page so nothing is selected, click in the empty space above the heading, and press Tab.
- Tab moves focus into the group once, onto 09:00. A second Tab leaves the whole group and goes to the Continue button. A radio group is one stop in the tab order, however many options it has.
- With focus in the group, the Right or Down arrow moves to the next time and selects it. Left or Up goes back. The arrows step over the taken times.
- The arrows cross from the Morning fieldset into the Afternoon one, since all nine radios are one group.
- Space selects the focused radio if nothing is selected yet.
None of this needs a line of JavaScript, and it matches what screen reader users expect from a radio group.
Check it worked
From 09:00, press the Right arrow twice. Focus and selection go 09:20, then 10:30, never stopping on 09:40. Press Tab: focus goes to Continue, and pressing Shift and Tab brings you back to 10:30, the selected time, not to 09:00.
Step 3 · Turn the radios into chips
Now restyle the labels as chips and hide the round radio dots. The dot must disappear visually only. The <input> stays in the page, keeps focus and keeps its state, which is what the keyboard and screen readers use. So make it transparent and one pixel in size rather than using display: none, which would remove it from the keyboard order and the accessibility tree.
Write the base styles and the chip:
cat > style.css <<'CSS'
:root {
--text: #1b1f24;
--text-muted: #5a6270;
--surface: #ffffff;
--canvas: #f6f7f8;
--border: #7d8592;
--line: #d5d9df;
--accent: #0f5e5a;
--accent-tint: #e3f0ee;
--on-accent: #ffffff;
}
* { box-sizing: border-box; }
body {
margin: 0;
background: var(--canvas);
color: var(--text);
font-family: system-ui, sans-serif;
font-size: 1rem;
line-height: 1.5;
}
main { max-width: 26rem; margin: 0 auto; padding: 1rem; }
h1 { font-size: 1.5rem; margin: 0 0 0.25rem; }
.service, .fallback { color: var(--text-muted); font-size: 0.875rem; margin: 0 0 1.5rem; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.day > legend { font-size: 1.125rem; font-weight: 600; margin-bottom: 1rem; padding: 0; }
.period { margin-bottom: 1.5rem; }
.period > legend { color: var(--text-muted); font-size: 0.8125rem; margin-bottom: 0.5rem; padding: 0; }
.slots { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.slot {
position: relative;
display: inline-flex;
align-items: center;
gap: 0.375rem;
min-height: 3rem;
min-width: 5.5rem;
padding: 0.5rem 0.875rem;
border: 1px solid var(--border);
border-radius: 0.5rem;
background: var(--surface);
font-variant-numeric: tabular-nums;
cursor: pointer;
}
.slot input {
position: absolute;
width: 1px;
height: 1px;
margin: 0;
opacity: 0;
pointer-events: none;
}
.tick { display: none; }
button[type="submit"] {
min-height: 3rem;
width: 100%;
border: 0;
border-radius: 0.5rem;
background: var(--accent);
color: var(--on-accent);
font: inherit;
font-weight: 600;
}
CSSThe input is shrunk to one pixel and made transparent, but it is still a real, focusable radio inside the label. min-height: 3rem (48 pixels at the default text size) matches the Larkfield slot spec and gives each chip a comfortable touch target, well above the 24 by 24 pixel minimum in WCAG 2.2 success criterion 2.5.8. font-variant-numeric: tabular-nums gives every digit the same width, so the times line up from chip to chip. fieldset { min-width: 0 } stops a fieldset from refusing to shrink below its content on narrow phones.
Check it worked
Reload. The round dots are gone and each time is a white rounded box with a grey edge, wrapping onto a second row on a narrow window. Click 10:30, then press the Right arrow: the selection still moves, even though nothing on screen shows it yet. The next step fixes that.
Step 4 · Show the selected slot with a tick
The label needs to look different when its radio is checked. The :has() selector lets a parent react to its child's state, so .slot:has(input:checked) matches the chip around the checked radio. It works in current Chrome, Edge, Firefox and Safari.
The Larkfield design fills the selected slot with the accent colour and adds a tick, because selection must not rely on colour alone (WCAG 2.2 success criterion 1.4.1). Someone who cannot tell teal from grey, or who uses a high-contrast mode that replaces colours, still sees the tick. Draw it from two borders of the empty span, so it is part of the design and never read aloud:
cat >> style.css <<'CSS'
.slot:has(input:checked) {
background: var(--accent);
border-color: var(--accent);
color: var(--on-accent);
font-weight: 600;
}
.slot:has(input:checked) .tick {
display: inline-block;
width: 0.375rem;
height: 0.75rem;
margin: 0 0.125rem 0.125rem 0;
border: solid currentColor;
border-width: 0 2px 2px 0;
transform: rotate(45deg);
}
CSSThe tick uses currentColor, so it always matches the text colour, white on the accent fill. Because the tick appears instead of taking up space beforehand, the selected chip grows by a few pixels. That is why the chips have a min-width: the row rarely reflows when the selection changes.
Check it worked
Reload and click 10:30. The chip turns dark teal with white bold text and a small tick before the time. Click 11:00: the tick and fill move to 11:00 and 10:30 goes back to white. Squint at the screen, or turn on your system's greyscale filter: you can still pick out the selected chip by its tick.
Step 5 · Make keyboard focus visible
The hidden input still receives focus, but its focus ring is invisible along with it. Without a replacement, a keyboard user cannot tell where they are, which fails WCAG 2.2 success criterion 2.4.7. Draw the ring on the label instead, using :focus-visible so it appears for keyboard use and not after every mouse click:
cat >> style.css <<'CSS'
.slot:has(input:focus-visible) {
outline: 3px solid var(--accent);
outline-offset: 2px;
}
button[type="submit"]:focus-visible {
outline: 3px solid var(--accent);
outline-offset: 2px;
}
CSSoutline-offset: 2px leaves a gap between the chip and the ring, so the ring is visible on the white chips and on the teal selected one. An outline also takes no space, so the layout does not move when focus arrives.
Check it worked
Reload, click in the empty space above the heading and press Tab. A thick teal ring with a small gap surrounds 09:00. Press the Right arrow: the ring and the selection both move to 09:20. Click a chip with the mouse instead: it is selected, and in Chrome and Edge no ring appears. Other browsers decide for themselves whether a mouse click shows a ring, so Firefox or Safari may differ.
Step 6 · Style the taken slots
The taken chips are already disabled and labelled, so this step is only about looks. Make them clearly unavailable without making them unreadable. A dashed edge and a struck-through time say "not this one" without using colour alone, and the word Taken says it in plain language:
cat >> style.css <<'CSS'
.slot:has(input:disabled) {
border-style: dashed;
background: transparent;
color: var(--text-muted);
cursor: not-allowed;
text-decoration: line-through;
}
.slot .taken {
font-size: 0.8125rem;
text-decoration: none;
display: inline-block;
}
CSSDisabled controls are exempt from the WCAG contrast minimum, but people still need to read them, so the text stays in text-muted, which measures about 5.7:1 on the canvas background. The Taken word is not struck through, because display: inline-block stops the parent's line from reaching it, so it stays readable.
A note on the trade-off. A disabled radio is skipped by Tab and the arrow keys, so a keyboard user moving through the times never lands on 09:40. Screen reader users still meet it when they read the page line by line, as "09:40 Taken" with a disabled or unavailable state. That is the behaviour you want for a time nobody can book. If a product needs taken slots to be focusable, for example to explain why, that is a different pattern built with aria-disabled and extra script, and worth a design discussion first.
If the app is offered in more than one language, such as English with Yoruba, Swahili or French, keep the word in the label and translate it with the rest of the page. Do not replace it with an icon only; an icon has no words to translate and nothing for a screen reader to read.
Check it worked
Reload. 09:40 and 14:40 have dashed edges, no white fill, grey struck-through times and an unstruck Taken beside them. The mouse pointer turns into a "not allowed" sign over them, and clicking does nothing. Arrow through the morning times again: 09:40 is never selected.
Step 7 · Require a choice before Continue
The first radio in the group carries required. For radio buttons, required on any one of them makes the whole group required, so the form cannot be sent until some time is picked. The browser shows its own message and moves focus to the group, again without script.
Check it worked
Reload so nothing is selected and click Continue. The browser shows a short message near the first time asking you to select an option (the exact words depend on your browser and its language), and the page does not change. Pick 10:30 and click Continue: the address bar now ends in ?slot=10%3A30, the time sent as form data with its colon encoded.
Step 8 · Test that 10:30 can be booked by keyboard
Clicking through by hand catches most problems once. A test catches them every time someone changes the CSS. Install Playwright, which drives a real browser from a script, into the demo folder. --with-deps also installs the system libraries Chromium needs on Linux, which can ask for your password:
cd ~/slot-picker-demo
npm init -y > /dev/null
npm install playwright@1.65.1
npx playwright install --with-deps chromiumThen write a test that behaves like a keyboard user: it presses Tab into the group and two Right arrows, and checks the outcome the patient would see and hear.
cd ~/slot-picker-demo
cat > test-keyboard.mjs <<'JS'
import { chromium } from 'playwright';
import assert from 'node:assert/strict';
const url = new URL('./index.html', import.meta.url).href;
const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width: 390, height: 844 } });
await page.goto(url);
// The groups have names a screen reader can read.
await page.getByRole('group', { name: 'Tue 9 Dec' }).waitFor();
await page.getByRole('group', { name: 'Morning' }).waitFor();
await page.getByRole('group', { name: 'Afternoon' }).waitFor();
// Nine times, two of them taken and announced as taken.
assert.equal(await page.getByRole('radio').count(), 9);
assert.ok(await page.getByRole('radio', { name: '09:40 Taken' }).isDisabled());
assert.ok(await page.getByRole('radio', { name: '14:40 Taken' }).isDisabled());
// Nothing chosen yet, so the form cannot be sent.
assert.equal(await page.locator('form').evaluate((f) => f.checkValidity()), false);
// Keyboard only: Tab into the group, then Right twice.
await page.keyboard.press('Tab');
assert.equal(await page.evaluate(() => document.activeElement.value), '09:00');
await page.keyboard.press('ArrowRight');
assert.equal(await page.evaluate(() => document.activeElement.value), '09:20');
await page.keyboard.press('ArrowRight');
assert.equal(await page.evaluate(() => document.activeElement.value), '10:30', 'the taken 09:40 is skipped');
const ten30 = page.getByRole('radio', { name: '10:30' });
assert.ok(await ten30.isChecked(), '10:30 is selected');
assert.equal(await page.locator('input[name="slot"]:checked').count(), 1, 'only one time is selected');
// What a sighted patient sees: the tick, the accent fill and a focus ring.
const chip = page.locator('.slot', { has: ten30 });
assert.ok(await chip.locator('.tick').isVisible(), 'tick is shown');
assert.equal(await page.locator('.tick:visible').count(), 1, 'only one tick');
const look = await chip.evaluate((el) => {
const s = getComputedStyle(el);
return { bg: s.backgroundColor, outline: s.outlineStyle, height: el.getBoundingClientRect().height };
});
assert.equal(look.bg, 'rgb(15, 94, 90)', 'accent fill');
assert.equal(look.outline, 'solid', 'focus ring on the chip');
assert.ok(look.height >= 48, 'target at least 48px tall');
// Tab leaves the group in one press and lands on Continue.
await page.keyboard.press('Tab');
assert.equal(await page.evaluate(() => document.activeElement.textContent), 'Continue');
// The form is now valid and sends 10:30.
assert.equal(await page.locator('form').evaluate((f) => f.checkValidity()), true);
await page.keyboard.press('Enter');
await page.waitForURL(/slot=10%3A30/);
// No sideways scrolling on a phone-sized screen.
const overflow = await page.evaluate(() => document.documentElement.scrollWidth > document.documentElement.clientWidth);
assert.equal(overflow, false);
await browser.close();
console.log('PASS: 10:30 booked by keyboard');
JS
node test-keyboard.mjsThe test uses getByRole with accessible names, the same role and name a screen reader is given, so a change that breaks a label or a legend breaks the test too. It checks a phone-sized viewport (390 by 844 pixels) because that is where most Larkfield patients book.
Check it worked
The last line of output is PASS: 10:30 booked by keyboard. To see the test fail for the right reason, remove disabled from the 09:40 radio in index.html and run node test-keyboard.mjs again: it stops with an AssertionError and no PASS line. Put disabled back and the test passes again.
Step 9 · Clean up
Remove the demo folder, which also removes the local Playwright install. The browser Playwright downloaded stays in its shared cache; npx playwright uninstall removes that too if you no longer need it.
cd ~
rm -rf ~/slot-picker-demoCheck it worked
ls ~/slot-picker-demo reports that there is no such file or directory.
Next steps
- Give the Continue button the full Larkfield treatment, with states and sizes, in build the Larkfield button in HTML and CSS.
- Add the Your details screen with labels, hints and an error summary in build accessible HTML forms.
- Lay out the whole screen, chips included, for wider windows with CSS Grid page layouts.
Part of these paths
Related tutorials
- Build the Larkfield button in HTML and CSSYou will build the Larkfield Clinic button as a real button element with primary, secondary and destructive variants drawn from colour tokens, hover, pressed, keyboard focus, disabled and loading states, a 48 pixel minimum height, and a Playwright script that checks every state's computed styles.
- How to Build Accessible HTML FormsYou will build a contact form that works with keyboards and screen readers, with real labels, grouped radio buttons, hints tied to their fields, autocomplete values, and an error summary that takes focus and links to each problem, checking the result against specific WCAG 2.2 criteria.
- How to Build Page Layouts with CSS GridYou will build a page with a header, sidebar, main area and footer using named grid areas, fill it with a grid of cards that adds and removes columns by itself, make one card span two columns, and change the layout for narrow screens.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials