Navbar
The top bar: logo and name on the left, the section links and, on the right, the actions (language, theme…). It is glass and sticks to the top when scrolling.
View on GitHubOn this page
Example
On the site it sticks to the top (position: sticky); here it is shown inside the frame.
<header class="gm-navbar gm-relative gm-rounded-sm">
<a class="gm-navbar__brand" href="#"><img class="gm-navbar__logo" src="logo.svg" alt="" width="48" height="48"><span>My site</span></a>
<nav class="gm-navbar__nav" aria-label="Main bar example">
<a href="#" aria-current="page">Home</a>
<a href="#">Services</a>
<a href="#">Contact</a>
</nav>
<div class="gm-navbar__actions">
<button type="button" class="gm-icon-btn" aria-label="Switch to dark mode"><i class="gmi gmi-moon" aria-hidden="true"></i></button>
</div>
</header>Parts
| Class | What it is |
|---|---|
.gm-navbar |
The bar: glass, sticky, as wide as the container |
.gm-navbar__brand |
Logo and name (link to home) |
.gm-navbar__logo |
The logo, 48 px (42 px on phones) |
.gm-navbar__nav |
The section links; the current page has aria-current="page" and is bold. On a one-page site, the section being viewed has aria-current="location" |
.gm-navbar__actions |
Buttons on the right (language, theme, account…) |
Glass logo
If the logo is made of glass (translucent, with shiny edges, like the GlassMarshmallow one), it barely shows on a light background. Add .gm-glass-logo: in light mode it gets a thin white border and the medium shadow outside, and the glass stays clean, as in dark mode; in dark mode nothing changes. It also works outside the navbar, for example in a card.
<img class="gm-navbar__logo gm-glass-logo" src="logo.svg" alt="" width="48" height="48">Without a logo and floating on phones
For single-page sites. On computers, without a logo: the links in the center and the theme button on the right (.gm-navbar--centered). On phones, no bar: only the round glass buttons remain, floating at the top right (.gm-navbar--floating), and the menu button (.gm-navbar__menu) opens the full-screen menu.
<header class="gm-navbar gm-navbar--centered gm-navbar--floating gm-relative gm-rounded-sm">
<nav class="gm-navbar__nav" aria-label="Centered bar example">
<a href="#" aria-current="page">Home</a>
<a href="#">About me</a>
<a href="#">Skills</a>
</nav>
<div class="gm-navbar__actions">
<button type="button" class="gm-icon-btn" aria-label="Switch to dark mode"><i class="gmi gmi-moon" aria-hidden="true"></i></button>
<button type="button" class="gm-icon-btn gm-icon-btn--glass gm-navbar__menu" aria-label="Open menu"><i class="gmi gmi-list" aria-hidden="true"></i></button>
</div>
</header>This is how it looks on phones (make the window narrower than 860 px to see it in the top bar):
<div class="gm-relative gm-overflow-hidden gm-rounded-sm" style="height: 10rem; background: var(--gm-backdrop-lights), var(--gm-backdrop-bg)">
<div class="gm-absolute gm-flex gm-gap-3" style="top: 0.75rem; right: 0.75rem">
<button type="button" class="gm-icon-btn gm-icon-btn--glass" aria-label="Switch to dark mode"><i class="gmi gmi-moon" aria-hidden="true"></i></button>
<button type="button" class="gm-icon-btn gm-icon-btn--glass" aria-label="Open menu"><i class="gmi gmi-list" aria-hidden="true"></i></button>
</div>
</div>Change the colors
With variables on the bar:
| Variable | What it changes |
|---|---|
--gm-header-bg |
The background (a color, with transparency if you want glass) |
--gm-header-filter |
The glass blur (blur(24px); none to remove it) |
--gm-header-border |
The bottom line |
--gm-header-shadow |
The shadow |
--gm-nav-size |
The link size (0.88 rem; 1 rem in the bar without a logo) |
--gm-nav-link |
The link color |
--gm-nav-link-hover |
The link color on hover (a color or a gradient). By default, the accent: the strong one by day (dark pink, 8.6:1) and the normal one at night (blue, or turquoise with gm-accent-turquoise) |
So the text reads well on the new background, the easiest way is to fix the mode of the bar with data-theme: a dark bar on a light page (data-theme="dark") or a pastel with black text (data-theme="light").
<div class="gm-grid gm-gap-4">
<header class="gm-navbar gm-navbar--centered gm-relative gm-rounded-sm" data-theme="dark">
<nav class="gm-navbar__nav" aria-label="Dark bar example">
<a href="#" aria-current="page">Home</a><a href="#">About me</a><a href="#">Skills</a>
</nav>
<div class="gm-navbar__actions"><button type="button" class="gm-icon-btn" aria-label="Switch to light mode"><i class="gmi gmi-sun" aria-hidden="true"></i></button></div>
</header>
<header class="gm-navbar gm-navbar--centered gm-relative gm-rounded-sm" data-theme="light" style="--gm-header-bg: var(--gm-mint); --gm-header-border: transparent; --gm-header-shadow: 0 4px 24px rgba(0, 0, 0, .08)">
<nav class="gm-navbar__nav" aria-label="Mint bar example">
<a href="#" aria-current="page">Home</a><a href="#">About me</a><a href="#">Skills</a>
</nav>
<div class="gm-navbar__actions"><button type="button" class="gm-icon-btn" aria-label="Switch to dark mode"><i class="gmi gmi-moon" aria-hidden="true"></i></button></div>
</header>
</div>On hover
Hover over the links: in the first bar they take the accent color (pink by day, blue at night); in the second, a gradient from lavender to pink.
<div class="gm-grid gm-gap-4">
<header class="gm-navbar gm-navbar--centered gm-relative gm-rounded-sm" style="--gm-nav-link-hover: var(--gm-accent)">
<nav class="gm-navbar__nav" aria-label="Accent color example">
<a href="#" aria-current="page">Home</a><a href="#">About me</a><a href="#">Skills</a>
</nav>
</header>
<header class="gm-navbar gm-navbar--centered gm-relative gm-rounded-sm" data-theme="light" style="--gm-nav-link-hover: linear-gradient(90deg, var(--gm-lavender-700), var(--gm-pink-700))">
<nav class="gm-navbar__nav" aria-label="Gradient example">
<a href="#" aria-current="page">Home</a><a href="#">About me</a><a href="#">Skills</a>
</nav>
</header>
</div>To change the accent color of the whole site (also buttons, focus and fields), see Another accent color.
For the whole site, put the variables in :root (and the night ones in [data-theme="dark"]), as in CSS variables.
Like the one on this site
This documentation's bar combines parts that work for any site with many pages:
gm-navbar__start: the brand and the links together on the left; the rest (search, actions) stays on the right.gm-navbar__icon: an icon link in the actions, like the GitHub one, with a 44 px target.gm-glass-logo--backdrop(optional): the glass logo with the home page lights behind it in light mode, instead of the shadow. This site's bar does not use it: its logo has the clean glass ofgm-glass-logo.gm-search--collapse-lg(on the search): it turns into the magnifying glass up to 1100 px instead of 860 px, for bars with many or long links (like this one in Spanish), and between 1100 and 1300 px the field gets narrower if needed so it never covers a link.gm-navbar--dense: on phones, brand, logo and buttons closer together so search, language and theme fit; below 360 px, only the logo (screen readers still read the name).
<header class="gm-navbar gm-navbar--dense">
<div class="gm-navbar__start">
<a class="gm-navbar__brand" href="/"><img class="gm-navbar__logo gm-glass-logo" src="logo.svg" alt=""><span>GlassMarshmallow</span></a>
<nav class="gm-navbar__nav" aria-label="Main">…</nav>
</div>
<div class="gm-search gm-search--navbar gm-search--collapse-lg" role="search">…</div>
<div class="gm-navbar__actions">
<a class="gm-navbar__icon" href="https://github.com/…" aria-label="GitHub"><svg aria-hidden="true">…</svg></a>
…
</div>
</header>On phones
Below 860 px, the .gm-navbar__nav links are hidden and move to the tab bar at the bottom. Between 860 and 1024 px the name next to the logo is hidden so everything fits.
Accessibility
- Links go in a named
<nav>(aria-label="Main") and the current page is marked witharia-current="page", which also shows in bold. - Each link is 44 px tall (WCAG 2.5.5).
- On hover or press, links take the accent color: dark pink by day and blue at night, both 7:1 or more (AAA).
- Focused items are not hidden behind the bar: the page leaves room when scrolling (WCAG 2.4.12).