Menu
CoddyTech

Choice Card States

Part of the Responsive UI Patterns section of Coddy's Tailwind CSS journey. Lesson 37 of 55.

A selectable card should retain a real input and a useful label. The parent can react to native descendant state with has-checked:. Unlike peer-checked:, which styles a later sibling, this pattern styles the ancestor containing the checked control.

<label class="block font-normal has-checked:font-semibold"><input type="radio" name="delivery"> Printed guide</label>

The example makes a checked choice card semibold while keeping a native radio inside its label. Related radio inputs share a name so the browser provides exclusive selection. No custom state handler is needed for this interaction.

Use a base surface for unselected cards and state overrides for selected cards. Include a non-color cue when practical. Test movement between options so the previous card’s presentation is restored.

challenge icon

Challenge

Medium

Use white backgrounds for the two native radio choice cards. Give only the card containing the checked radio a #dbeafe background. Preserve the enclosing labels and shared radio name, and transfer the cue when the other choice is selected.

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 id="morningCard" class="block p-4 bg-white"><input id="morning" type="radio" name="session"> Morning studio</label><label id="eveningCard" class="block p-4 bg-white"><input id="evening" type="radio" name="session"> Evening studio</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