Selectable Form Options
Part of the Responsive UI Patterns section of Coddy's Tailwind CSS journey. Lesson 18 of 55.
A native checkbox already supplies keyboard interaction and checked state. Add a visual cue to its caption by marking the input with peer and styling a following sibling with peer-checked:. Keep the real input and its label relationship.
<label><input type="checkbox" class="peer"><span class="font-normal peer-checked:font-semibold">Include a printed guide</span></label>In the example, checking the option makes its caption semibold. The peer marker goes on the control whose state matters; the conditional utility goes on the caption. The ordinary sibling pattern requires the caption to come after the input.
Base styles describe the unchecked state, and checked variants describe the selected state. Use an underline or another non-color cue where useful, and verify that unchecking restores the base presentation.
Challenge
MediumKeep the native updates checkbox and its enclosing label. Its following caption must be normal-weight and undecorated when unchecked, then bold and underlined when checked. Restore both base styles after unchecking.
Preserve the supplied content, semantic elements and IDs. Edit the requested utility classes. Press Run preview after edits, then Check/Run code to grade the result. Supplied JavaScript is read-only.
Try it yourself
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Interface workshop</title><link rel="stylesheet" href="./styles.css"></head><body>
<label class="block p-4"><input id="updates" type="checkbox" class="peer"> <span id="caption" class="font-normal no-underline">Send workshop updates</span></label>
</body></html>
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Responsive UI Patterns
1Page Shells
Growing Page ShellsFlexible Content RailsBounded Scroll RegionsFull-Bleed RegionsRecap: Page Shells4Form Layouts
Responsive Field GroupsFocused Field GroupsSelectable Form OptionsNative Validation CuesRecap: Form Layouts2Navigation Patterns
Wrapping NavigationCurrent Page CuesNative Menu DisclosuresKeyboard Skip LinksRecap: Navigation5Data Tables
Scrollable Data TablesPredictable Table ColumnsRow State PresentationSticky Table HeadersRecap: Data Tables8Interactive Panels
Expanded Control CuesChoice Card StatesFocus-Aware Help PanelsContent-Aware Empty StatesRecap: Interactive Panels11Project: Event Portal
Portal ShellSession Browser