Expanded Control Cues
Part of the Responsive UI Patterns section of Coddy's Tailwind CSS journey. Lesson 36 of 55.
A supplied interactive control can expose its state through aria-expanded and its target through aria-controls. Tailwind’s built-in aria-expanded: variant applies when expanded is true. Keep the actual state update in the supplied behavior.
<button aria-expanded="true" aria-controls="help" class="font-normal aria-expanded:font-semibold">Help</button><section id="help">Help content</section>The example changes a disclosure control’s weight while its panel is open. The state remains open after hover ends, so hover styling is not a substitute. Use the semantic button and preserve its controlled-panel ID.
Provide an explicit collapsed base and expanded overrides. Test opening and closing rather than checking only one screenshot. A visual cue should follow the current state, not permanently decorate whichever control was clicked first.
Challenge
MediumStyle the supplied travel disclosure button with normal weight and no underline when collapsed, then bold weight and an underline when expanded. Preserve its native button, aria-controls relationship and supplied behavior. Both cues must return to their base values when closed.
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>
<button id="toggle" aria-expanded="false" aria-controls="panel" class="font-normal no-underline">Travel details</button><section id="panel" hidden>Bus and train information</section>
<script src="./controls.js"></script>
</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