Menu
CoddyTech

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 icon

Challenge

Medium

Keep 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>
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Responsive UI Patterns