learn.web Back to the curriculum ↗

HTML / CSS / JavaScript / 01

HTML that works harder

Use landmarks, forms, dialog, popover, disclosure, and native controls before reaching for custom widgets.

Time
70 min
Mode
Learn → Make → Check
Path
Modern Web Platform

By the end, you can…

Start with behavior, not appearance

HTML is not a collection of neutral boxes. A button already knows how to receive focus, react to keyboard and pointer input, participate in forms, and announce itself to assistive technology. Rebuilding that behavior on a div means accepting responsibility for every interaction the browser previously handled.

Before choosing an element, write the user action as a sentence: submit information, navigate somewhere, reveal optional content, choose one option, or open a temporary layer. That verb usually points to a native element. Use ARIA to clarify a gap, not to repaint the identity of convenient markup.

Progressive enhancement in three layers

Layer one is meaningful HTML that completes the essential task. Layer two is CSS that improves composition without changing meaning. Layer three is JavaScript that adds convenience while preserving links, forms, history, and browser conventions.

Test the boundary by blocking the script, tabbing through the interface, and inspecting the accessibility tree. A resilient experience may be less polished without enhancement, but it must remain understandable and useful.

Working example
<button popovertarget="lesson-tip">Why native?</button>
<aside id="lesson-tip" popover>
  Focus, dismissal, and top-layer behavior are built in.
</aside>

Your studio task

Make — Rebuild one custom menu with native disclosure or popover HTML.

  1. Find one custom menu, disclosure, modal, or clickable div.
  2. Name the user action and select the closest native element.
  3. Rebuild the smallest version with HTML first, then style it.
  4. Disable JavaScript and complete the task with a keyboard.
Definition of done

It remains understandable before JavaScript loads and exposes the right name, role, and state.

Open the interactive lesson with its workspace ↗

Knowledge check

A card navigates to a detailed page. What should its primary interactive element be?
  1. A div with role="button"
  2. A link with a real href
  3. A button with a click handler
Reveal answer (B)

Navigation changes location, so a real link communicates intent, supports browser conventions, and works before JavaScript.

A “Show more” control reveals optional content. Which element fits best?
  1. A span with a click handler
  2. details with a summary
  3. A div with tabindex="0"
Reveal answer (B)

details/summary provides native disclosure: toggle behavior, keyboard support, and semantics for free.