Etch component

Header 1

Header 1

Copy Header 1

Configurator settings

Change a setting in the configurator to include it.

Optional. Copies the component under its own name, such as News Card Alpha for a site.

Documentation

The site's header: the logo, a menu of links and dropdowns and, up to 992px wide, a Menu button that opens the menu in a panel. A MAC Subheader 1 can sit above it.

How to use it

  1. Try the settings in the preview's Props tab, then copy the configured JSON and paste it in Etch. The same settings are the header's props.
  2. Its look, its layout and its subheader on mobile are CSS recipes, below. Try them in the preview's Styles tab, then paste the ones you pick in the site's main stylesheet.
  3. Edit the sample menu in the menu slot: MAC Menu Link 1s for links and MAC Menu Dropdown 1s for dropdowns. For a call to action, show the last link as a button with its Show As.
  4. Change the logo once for the site, in MAC Logo 1, which the footers and the drawer menus show too.
  5. Set the texts in the site's language: Skip Link Text, Logo Aria Label ({site.name} gives the site's name), and the Menu Button group's First Label and Second Label. With the same text in both, as "Menu" by default, the button shows it once; with two texts, First Label shows while the menu is closed and Second Label while it's open.
  6. For a bar above the header, put a MAC Subheader 1 in the subheader slot.

What it does

  • Its look is Bar, a full-width band in the page's color with a line under it, unless the Floating recipe makes it a box with rounded corners in the page's color.
  • Its layout has the logo at the start and the links at the end, unless a recipe puts the links right after the logo (Logo and links) or the logo in the middle with the links beside it (Centered logo) or at the header's edges (Centered logo, links at the edges). Up to 992px wide, every layout has the logo at the start and the Menu button at the end.
  • On Scroll: the header scrolls away with the page (Scrolls Away), stays at the top (Sticky), hides once visitors scroll down past Hide At (200px) and comes back when they scroll up (Sticky, Hides Going Down, the default), or hides past Hide At for good (Sticky, Hides for Good). On a sticky header, Sticky Subheader keeps the subheader above the bar, and with the Floating recipe Float on Scroll keeps the box flush with the window's top edge, its top corners square, until the page scrolls, then floats it a little below the edge with all its corners rounded. Without the recipe, Float on Scroll does nothing.
  • Overlay puts the header over the top of the page, for a hero image behind it. Over the Page, First Section Below It also moves the first section down by the header's height. With Overlay, a sticky header always keeps its subheader above the bar, so the Sticky Subheader setting appears only with Overlay off.
  • Mobile Menu, up to 992px wide: Off Canvas, a panel that slides in from an edge (Off Canvas Direction), or Reveal, which opens down from the header. Backdrop dims the page behind either. Mobile Dropdowns open as an Accordion or Stacked, a panel of their own with a back button. While the menu is open, the rest of the page is out of reach of the keyboard and screen readers, and the Menu button or Escape closes it.
  • On desktop, dropdowns open on hover and click, or on click only (Desktop Dropdowns Open On), and animate as separate dropdowns or as one panel that morphs from one to the next (Desktop Dropdowns Animation).
  • Show Label off, in the Menu Button group, shows only the Menu button's icon, and its text stays the button's name for screen readers.

Good to know

  • Use one header per page: the Menu button opens the menu by its id, mac-menu-1, and the menu's script starts one menu.
  • Turn off ACSS's Offset Content Automatically, or the first section gets extra space on top: the header already makes room for itself, or covers the page on purpose with Overlay.
  • Above 992px the links sit beside the logo, so they all have to fit there. If they don't, use fewer or shorter links.
  • The Menu button's text, "Menu", is also its name for screen readers, which hear whether the menu is open. Aria Label in the Menu Button group, empty by default, gives it a longer name, which should start with that text.
  • Overlay's offset moves the first element in main's first child, so main has to come right after the header.
  • With Skip Link on (the default), its script adds a link for keyboard users, in the words of Skip Link Text, that jumps to the page's main. It also sets --header-height on the page, for sticky elements and anchor offsets.
  • The look's colors, corners and padding and the logo's height are CSS variables. The Reference lists them with the props and slots.
  • The Reveal menu opens right below the bar with Bar and --space-xs below the box with Floating. --mac-menu-1-reveal-gap, set on the header or its menu, makes it that space in every look.

CSS recipes

--mac-header-1-look, --mac-header-1-layout and --mac-header-1-subheader-on-mobile take a keyword for the header's look, its layout and its subheader on mobile. A recipe changes every Header 1 on the site. Paste it in the site's main stylesheet, which Etch prints after the components' styles, and paste two for both, such as Floating and a layout. The keyword goes on :root, or on an element around the header, never on the header itself, since the header reads it from the elements around it. A browser without container style queries keeps Bar's look and the default layout.

Floating

For a lighter header, a box with rounded corners in the page's color, with some space around it.

/* Header 1 as a box with rounded corners */
:root {
  --mac-header-1-look: floating;
}

Logo and links

For a short menu, its links right after the logo.

/* Header 1's links right after the logo */
:root {
  --mac-header-1-layout: logo-links;
}

Centered logo

For a header led by the brand, the logo in the middle with the links on both sides of it, on screens over 992px wide.

/* Header 1's logo in the middle, its links beside it */
:root {
  --mac-header-1-layout: centered;
}

Centered logo, links at the edges

For a wide screen, the logo in the middle with the links at the header's edges, on screens over 992px wide.

/* Header 1's logo in the middle, its links at the edges */
:root {
  --mac-header-1-layout: centered-sides;
}

Subheader hidden on mobile

For a subheader that would crowd a small screen, hidden up to 992px wide.

/* Header 1's subheader hidden up to 992px wide */
:root {
  --mac-header-1-subheader-on-mobile: hidden;
}

Reference

Read from the component's JSON, so it's always current.

Loading the reference