Navigation & Menus
Ten navigation components - besides the theme switch and scroll-to-top, every one of them works without JavaScript. This page explains the mechanisms and lists the classes; ready-made blocks to copy are in the examples.
1. What to choose
Every component below is an independent SCSS module - if you don't use one, simply don't load it into your bundle.
| Component | What for | What it's built on | Examples |
|---|---|---|---|
.navbar |
The page's main bar. | Flexbox | navbar |
.navbar-menu-offcanvas |
A side-sliding menu on mobile. | Checkbox Hack | navbar |
.mega-menu |
A wide, multi-column menu. |
<details> + Anchor Positioning
|
mega menu |
.dropdown |
A narrow menu below a button. |
<details> or the Popover API
|
dropdown |
.breadcrumb |
A path back through the hierarchy. | Flexbox | hero sections |
.pagination |
Paging through result pages. | Flexbox | pagination |
.topbar |
A narrow bar above the navbar (contact, language). | Flexbox | navbar |
.language-switch |
A language switcher with flags. | Popover API | language switch |
.theme-switch |
A light/dark theme switch. | Checkbox + JS | navbar |
.scroll-to-top |
Return to the top of a long page. | JS (visibility) | widgets |
2. Navbar - structure
Three levels of nesting and nothing more:
<nav class="navbar"> wraps
.navbar-container (that's what constrains the
content width), and inside sit the brand and the menu. The
bar's height lives in the --navbar-h variable,
since other components reference it too - including the
admin panel's sidebar.
<nav class="navbar">
<div class="container navbar-container">
<a href="/" class="navbar-brand">Logo</a>
<div class="navbar-menu">
<a href="/offer" class="navbar-item">Offer</a>
<a href="/contact" class="navbar-item">Contact</a>
</div>
</div>
</nav>
| Class | On | What it does |
|---|---|---|
.navbar |
<nav> |
The bar: background, shadow, height --navbar-h.
|
.navbar-container |
<div> inside the navbar |
Spreads the brand and menu to opposite edges. Combine
with .container to cap the width.
|
.navbar-brand |
<a> |
Logo or name. Usually links to the homepage. |
.navbar-menu |
<div> |
The link container. Its presence activates the active-item highlighting module. |
.navbar-item |
<a> |
A single link. Has min-height: 44px -
the touch-target requirement.
|
.navbar-sticky |
<nav> |
Pins the bar to the top on scroll. Don't combine it with the overlay variants - see pitfall #1. |
.logo-light / .logo-dark |
<img> inside the brand |
A pair of logos - the framework shows whichever matches the theme. |
.is-active |
.navbar-item |
The current page. Don't write it into the markup - see section 6. |
.is-scrolled |
<nav> |
Applied by JS after scrolling. You never set it yourself. |
.is-hidden |
.navbar-sticky |
Hides the pinned bar upward when scrolling down. Also
applied by JS, after 100px of scrolling. In Chrome/Edge
144+ CSS hides the bar as well (a scroll-state
query) - from the first pixel down, also without
molique-script.js. An open mobile menu keeps
the bar in place in both cases.
|
3. Overlay variants
Two variants place the navbar on the content
instead of above it, so a hero photo can start at the very
top of the window. Both work the same way:
position: absolute over the hero, and once
scrolled JS applies .is-scrolled, which switches
the bar to position: fixed with the theme's background.
| Class | Look over the hero | After scrolling |
|---|---|---|
.navbar-transparent |
No background, white links. | Theme background, bar flush against the edge. |
.navbar-pill |
A pill pulled away from the edge, with its own dark background. | Unfolds into a regular bar flush against the edge. |
Pill variables
The pill has separate variables for each state,
not one shared set. This isn't an oversight: an inline style
beats a class rule, so one shared variable set via
style="…" would lock the second state forever.
| Variable | Default | Controls |
|---|---|---|
--navbar-pill-bg |
dark | Background over the hero. Dark even in the light theme - it sits on a photo. |
--navbar-pill-color |
white | Link color over the hero. |
--navbar-pill-bg-scrolled |
theme background | Background after scrolling. |
--navbar-pill-color-scrolled |
theme text | Link color after scrolling. |
--navbar-pill-padding-x |
32px |
How far the pill sits from the window edge. |
--navbar-pill-padding-x-scrolled |
16px |
Offset after scrolling. |
<nav class="navbar navbar-pill" style="
--navbar-pill-bg: #4c1d95;
--navbar-pill-bg-scrolled: #1e293b;
--navbar-pill-color-scrolled: #fff;">
<div class="container navbar-container">…</div>
</nav>
<!-- The navbar is out of flow, so push the content below it down -->
<header style="padding-top: calc(var(--navbar-h) + 4rem)">…</header>
Both variants in action: navbar examples.
4. Offcanvas (mobile menu)
A menu sliding in from the side of the screen, with no
line of JavaScript. The whole mechanism is a hidden
checkbox: the hamburger and the backdrop are labels
(<label for>) for the same field, and CSS
reacts to :checked.
That's where the one hard requirement comes from: the
checkbox must be a sibling of the hamburger and the
menu, i.e. sit inside .navbar-container. CSS
selectors can only reach "sideways and downward" - if you
move the checkbox before <nav>, the menu
stops opening.
| Class | On | What it does |
|---|---|---|
.navbar-offcanvas-toggle |
<input type="checkbox"> |
The hidden toggle - the menu's open state. Requires an id.
|
.navbar-toggle |
<label for> |
The hamburger. Contains three empty
<span>s - those are the icon's lines.
|
.navbar-offcanvas-backdrop |
<label for> |
The dimmed backdrop. Since it's a label, clicking it closes the menu too - also with no JS. |
.navbar-menu-offcanvas |
.navbar-menu |
Turns the menu into a panel that slides in from the side on mobile. |
Complete markup to copy: navbar examples.
5. Dropdown menus
The mega menu and dropdown are built on native
<details>: <summary> is
the button, and the sibling below is the panel. That's what
makes them open on click, not on hover, so
keyboard support works with nothing extra added.
Closing on a click outside the panel is an invisible,
full-screen "cover" present only while
<details> is open - the click lands on it,
it forwards the click to <summary>, and
that natively closes the panel.
A name attribute instead of a script
Give every menu in one bar the same
name="nav-mega", and the browser will make sure
at most one stays open. With a single instance you won't
see the effect - it only kicks in from the second one on.
<details class="mega-menu" name="nav-mega">
<summary class="navbar-item mega-menu-trigger">Components</summary>
<div class="mega-menu-content">
<div class="mega-menu-group">
<h6 class="mega-menu-col-title">Category</h6>
<a href="#" class="mega-menu-link">Link</a>
</div>
</div>
</details>
| Class | What it does |
|---|---|
.mega-menu |
On <details>. The whole component. |
.mega-menu-trigger |
On <summary>. Combine with
.navbar-item so it looks like the rest of the links.
|
.mega-menu-content |
The panel. Anchors itself to the trigger via Anchor Positioning. |
.mega-menu-group |
A column inside the panel. |
.mega-menu-col-title |
The column's heading. |
.mega-menu-col-icon |
An icon next to the column heading. |
.mega-menu-link |
A link within a column. |
.mega-menu-featured |
A highlighted promo block in the panel. Inside:
.mega-menu-featured-icon,
.mega-menu-featured-title,
.mega-menu-featured-text,
.mega-menu-featured-link.
|
.dropdown |
On <details>. The mega menu's narrow counterpart.
|
.dropdown-toggle |
On <summary>. |
.dropdown-menu |
The panel with the items. |
.dropdown-item |
A single item. |
.dropdown-header |
A label above a group of items: <div class="dropdown-header">Move to</div>. It is not an item, so it reacts to neither hover nor click, and its indent matches .dropdown-item. |
--dropdown-max-height |
The height limit of a [popover] menu, 45dvh by default. A longer list scrolls inside. Above 50% of the screen the menu may not fit on either side of the button. |
.dropdown-menu-end |
Aligns the panel to the button's right edge. |
Dropdowns outside the navbar
Inside a table, card, or modal, overflow will
clip a panel built on <details>. Use the
Popover-API variant instead: a plain
<button popovertarget="ID"> plus a
.dropdown-menu with a popover
attribute and that same id. The panel lands in
the top layer, so nothing clips it, and it anchors itself
to the button automatically - with no .dropdown
wrapper needed.
6. The rest of the components
Smaller navigation elements. Each one is its own SCSS module, so you simply skip the ones you don't use in your bundle.
Pagination
<ul class="pagination">
<li class="page-item is-disabled"><a class="page-link" href="#">Previous</a></li>
<li class="page-item is-active"><a class="page-link" href="#">1</a></li>
<li class="page-item"><a class="page-link" href="#">2</a></li>
<li class="page-item"><a class="page-link" href="#">Next</a></li>
</ul>
| Class | Component | What it does |
|---|---|---|
.pagination |
Pagination | The list of pages. On a <ul>. |
.pagination-modern |
Pagination | A variant with spaced-out, separate buttons. |
.page-item |
Pagination |
An item (<li>). Variants:
.is-active - the current page,
.is-disabled - an unavailable step.
|
.page-link |
Pagination | The clickable <a> inside an item. |
.breadcrumb |
Breadcrumbs | The path back. On an <ol> or <ul>. |
.breadcrumb-item |
Breadcrumbs |
A link in the chain; CSS draws the separator.
.is-active marks the current location.
|
.topbar |
Top bar | A narrow bar above the navbar - phone, email, language. |
.topbar-content |
Top bar | Spreads its content to the bar's edges. |
.topbar-list |
Top bar | A horizontal list of items with no bullets. |
.scroll-to-top |
Scroll to top |
A corner button. JS applies .is-visible
after scrolling - you never set it yourself.
|
.progress-container-fixed |
Reading bar | The progress bar's track, pinned to the top of the window. |
.progress-bar-reading |
Reading bar | The fill showing reading progress. Controlled by scroll. |
Language switch
Built on the Popover API, so the list lands in the top layer
and can't be clipped. Flags only as SVG files
from img/flags/ - emoji don't render on Windows,
and an external sprite won't work over file://.
| Class | What it does |
|---|---|
.language-switch |
The component's wrapper. |
.language-switch-trigger |
The button with popovertarget - flag and language code.
|
.language-switch-menu |
The list of languages. Combine with
.dropdown-menu and the
popover attribute.
|
.language-switch-item |
A single language; also .dropdown-item. |
.language-switch-flag |
The flag as an <img> from img/flags/. |
.language-switch-name |
The language's name next to the flag. |
.language-switch-check |
The mark next to the currently selected language. |
Theme switch
A light/dark slider, in practice always a neighbor of the
language switch in the navbar - that's why it's described
here rather than among the forms. Underneath it's a plain
<input type="checkbox"> wrapped in a
<label>, so the keyboard works natively.
id="theme-toggle" is mandatory
This is the only component in molique where a
specific id is part of the
contract - molique-script.js looks up
the element via
getElementById('theme-toggle'). Rename it or
duplicate it, and the switch stops working with no error
reported. For the same reason, a page can have
only one.
<label class="theme-switch" title="Switch theme">
<input type="checkbox" id="theme-toggle" class="theme-switch-input">
<div class="theme-switch-track">
<span class="theme-switch-thumb"></span>
<div class="theme-icon-wrapper">
<svg class="theme-icon icon-sun">…</svg>
<svg class="theme-icon icon-moon">…</svg>
</div>
</div>
</label>
| Class | What it does |
|---|---|
.theme-switch |
The wrapper, on a <label> - that's
why clicking anywhere in it toggles the theme.
|
.theme-switch-input |
The hidden checkbox holding the state. It's the one
that needs id="theme-toggle".
|
.theme-switch-track |
The slider's track - the visible bordered pill. |
.theme-switch-thumb |
The floating element that rides along the track. |
.theme-icon-wrapper |
The container for both icons inside the track. |
.theme-icon |
The shared icon style - size and transition. |
.icon-sun |
The light-theme icon. |
.icon-moon |
The dark-theme icon. |
| What the script does | Detail |
|---|---|
| Remembers the choice |
The molique-theme key in
localStorage.
|
| Respects the system setting |
On the first visit it reads
prefers-color-scheme. A saved user choice
takes priority.
|
| Switches the theme |
Sets data-theme on
<html> - that's the only thing that
distinguishes the themes.
|
| A smooth transition |
The View Transitions API does a GPU cross-fade. Older
browsers and
prefers-reduced-motion get an instant switch.
|
7. Active item
The navbar is usually a single file shared by every subpage,
so the current item can't be marked in the
markup - it would be marked identically everywhere.
This is handled by the
js/modules/molique-navbar-active.js module,
auto-loaded whenever a page has a .navbar-menu.
Gets .is-active |
When |
|---|---|
.navbar-item |
When its href points to the current address. |
.dropdown-item, .mega-menu-link |
The same - including inside dropdown panels. |
A panel's <summary> |
When the active link is nested inside - you can see which branch you're in. |
If the same page appears in several menus at once, every instance gets highlighted. The admin panel's vertical sidebar is handled by a separate module - see the Admin Panel.
8. Pitfalls
1
An overlay plus .navbar-sticky = the overlay disappears
.navbar-transparent and
.navbar-pill work because they're
outside the document flow
(position: absolute) - that's what lets
content sit underneath them. .navbar-sticky
does the opposite: it returns to the flow. It wins in
the cascade, and the whole overlay effect disappears.
<!-- WRONG - sticky cancels the overlay -->
<nav class="navbar navbar-transparent navbar-sticky">
<!-- RIGHT - pinning after scroll is already built in -->
<nav class="navbar navbar-transparent">
2 Content hides under an overlay navbar
Since the bar is out of flow, it doesn't reserve any space for itself - the page's first element will slide right under it. Intentional for a photo hero, not for a regular section. Push the content down by the bar's height.
<header style="padding-top: calc(var(--navbar-h) + 4rem)">…</header>
3 The offcanvas checkbox moved outside the container
It's tempting to drop the <input>
before <nav> "so it doesn't get in
the way". Then the menu stops opening and there's no
visible error - nothing just happens. CSS links the
checkbox to the menu with a sibling selector, so both
must sit inside the same .navbar-container.
4
.is-active hard-coded into the navbar markup
The navbar is often one file for the entire site. A hard-coded active item will be highlighted on every subpage - including the ones where you're somewhere else. Leave this to the module from section 6.
The same rule applies to the documentation sidebar
you're reading right now - that's why it's a single
partial with no .is-active in the code.
5 A dropdown clipped inside a table or a modal
A panel built on <details> is a
regular element in the tree, so
overflow: hidden or
overflow: auto on an ancestor will cut it
off. This typically happens inside
.table-wrapper and in modals. The fix is
the Popover-API variant described in section 5 - the
panel lands in the top layer, out of
overflow's reach.