mica
mica

Example

mica

Ordinary links, one quiet header. Try Menu when the container is narrow.

mica

Ordinary links, one quiet header. Try Menu when the container is narrow.

Narrow container

mica

Ordinary links, one quiet header. Try Menu when the container is narrow.

Nested navigation

Add compact dropdowns or rich link panels using the navigation menu pattern. The same groups become inline disclosures inside the mobile Menu.

Basic usage

Use a native header around m-header for the page banner. The custom element supplies layout and styling. Import the optional module for responsive collapse.

<script type="module" src="header.js"></script>
<header>
<m-header align="end">
  <a data-brand href="../index.html">mica</a>
  <nav id="primary-nav" aria-label="Primary">
    <a href="../index.html">Overview</a>
    <a href="button.html">Components</a>
    <a href="header.html" aria-current="page">Navigation</a>
    <a data-compact href="#usage">Get started</a>
  </nav>
  <div data-actions><a class="btn" data-variant="primary" href="#usage">Get started</a></div>
  <button type="button" data-menu popovertarget="primary-nav">Menu</button>
</m-header>
</header>

API

Content/markup contract

PartContractDescription
BrandDirect a[data-brand], optionalAuthored text, image, or logo. Supply an accessible name and a real destination.
NavigationOne direct nav containing direct links; opt into nested disclosures with data-navigation-menuGive it a distinct accessible label. For collapse it needs an ID matching the Menu button's popovertarget.
ActionsDirect [data-actions], optionalExisting buttons or links, aligned at the end. Hidden when collapsed; author equivalent destinations in the nav with data-compact when they must remain available.
Compact destinationDirect nav > a[data-compact], optionalVisible only in the collapsed panel. Use for secondary destinations represented by desktop actions. Each instance still needs its own unique IDs, if any.
Menu triggerDirect button[data-menu][popovertarget], optionalUse type="button" and a visible Menu label. Hidden until enhancement activates collapse. Without a correctly connected trigger the nav stays inline.

Attributes and state

NameTargetDefaultDescription
align="start | end"m-headerstartAligns desktop links within their flexible region. end means right in LTR and left in RTL. The compact panel starts at the top in both cases.
aria-current="page"Navigation linkApplication-owned current destination, with neutral fill and stronger text. Navigation uses ordinary Tab and Enter behavior.
aria-disabled="true"Navigation linkDimmed presentation only. Prefer omitting unavailable destinations. If shown, omit href and use role="link"; ARIA alone never prevents navigation.

Styling

PropertyDefaultDescription
--header-padvar(--space-sm)Block padding.
--header-guttervar(--space-md)Inline padding.
--header-gapvar(--space-md)Gap between brand, navigation, and actions.
--header-nav-alignstartDesktop link alignment; align="end" sets this to end.
--header-font-size0.875remLink text size.
--header-font-weight500Default link weight.
--header-strong-weight650Brand and current-page weight.
--header-target-height2.75remMinimum link height in the compact panel.

Responsive enhancement

header.js registers m-header. Below a container content width of 40rem, it turns the same authored nav into an automatic native popover and exposes the Menu button. The desktop action group moves out of the tab order with its hidden presentation. The module does not create links, clone navigation, choose the current page, or handle routing.

The panel aligns with the header, opens above when there is more room there, and scrolls internally if necessary. Escape and outside clicks dismiss it through the browser. Following a link also closes it; modified clicks retain normal new-tab behavior. On resize, focus moves out of any content being hidden to the Menu button, or from the disappearing Menu button to the first navigation link.

Omit the import or the Menu trigger to keep a wrapping inline header. Without JavaScript or Popover support, primary navigation remains visible and native links still work. Keep the nav free of an authored popover attribute; the module manages it only while collapsed. No custom events are emitted.

Accessibility and composition

Use one page-level banner, a labeled nav, and real links. Do not use role="menu" or menu-item roles for site navigation. Preserve brand, navigation, actions, then Menu in DOM order. Compact links should cover the destinations hidden with desktop actions; complex forms or controls are better placed in a separately authored drawer.

Keep the brand concise and use this pattern for a handful of destinations. For large navigation trees, compose a sidebar or drawer. Sticky positioning is consumer-owned: apply position: sticky; inset-block-start: 0 to the native header with a suitable stacking level.

← field validationnavigation menu →