Sub topic 3
The Priority Menu
Assume you know semantic HTML, CSS flexbox and media queries, and basic JavaScript event handling. A priority menu keeps important links visible and moves lower-priority links into a More menu when space runs out.
The Priority Menu
Use ResizeObserver to recalculate the layout when the navigation width changes. The script restores all links first, then moves links from the end until the visible list fits.
<nav class="priority" aria-label="Main navigation">
<ul class="priority-list">
<li><a href="/products">Products</a></li>
<li><a href="/pricing">Pricing</a></li>
<li><a href="/docs">Docs</a></li>
<li><a href="/blog">Blog</a></li>
</ul>
<details class="priority-more" hidden>
<summary>More</summary>
<ul class="priority-overflow"></ul>
</details>
</nav>
<script>
const nav = document.querySelector(".priority");
const list = nav.querySelector(".priority-list");
const more = nav.querySelector(".priority-more");
const overflow = nav.querySelector(".priority-overflow");
function update() {
while (overflow.firstChild) list.append(overflow.firstChild);
more.hidden = true;
while (list.scrollWidth > list.clientWidth && list.children.length > 1) {
more.hidden = false;
overflow.prepend(list.lastElementChild);
}
}
new ResizeObserver(update).observe(nav);
update();
</script>The link order expresses priority. Keep the most important links at the beginning. The native details element supplies keyboard support for opening and closing More.
Choosing the Right Pattern
| Pattern | Best fit | Main risk |
|---|---|---|
| Priority menu | Many links with clear importance | Hidden links are less discoverable |
| Hamburger menu | Secondary or infrequently used navigation | Adds an interaction step |
| Bottom tab bar | Three to five frequent destinations | Uses valuable screen space |
Choose based on item count, importance, and usage frequency. Do not hide a frequently used destination just to make the header look cleaner.
Combining Patterns Across Breakpoints
Use a wide-screen priority menu when several links deserve visibility. Switch to a hamburger menu at a narrow breakpoint when the header cannot support the row. Use a bottom tab bar separately for the small set of destinations people visit most often. Keep link names and destinations consistent across layouts.
> callout note > A media query can change presentation, but JavaScript must also respond to resizing. Test both resizing and device rotation.
Testing Navigation on Real Devices
Test with a keyboard, a screen reader, and touch input. Confirm that:
- Focus reaches every visible link and the More control.
- Enter and Space open controls as expected.
- The menu remains usable after rotation.
- Touch targets are at least 48 CSS pixels high.
- The most important links remain visible at common widths.
Exercise
Which link should move into More first?
Show answer
The lowest-priority visible link, usually the last link in the ordered list.