22 Pure CSS20 with JSPublished 2026-10-03Free · no sign-up
Every navigation pattern on one page: responsive, sticky and glass navbars, hamburger buttons and mobile menus, tabs that work without JavaScript, accordions, breadcrumbs, pagination and an app sidebar. Navigation components built to be found and used by everyone: a responsive navbar with a proper menu button, tabs that work without JavaScript, an FAQ accordion on native details, breadcrumbs, pagination and an app sidebar. Each one handles keyboard focus and tells screen readers where the visitor is.
A header with a logo, links and a call-to-action that turns into a menu button on small screens. The button is a real button with aria-expanded and aria-controls, so screen readers announce whether the menu is open, and Escape closes it. Resize the editor preview below 600px to see the mobile menu.
var toggle = document.querySelector('.ttn-toggle');
var menu = document.getElementById('ttn-menu');
function setOpen(open) {
menu.classList.toggle('is-open', open);
toggle.setAttribute('aria-expanded', open ? 'true' : 'false');
toggle.textContent = open ? 'Close' : 'Menu';
}
toggle.addEventListener('click', function () { setOpen(!menu.classList.contains('is-open')); });
document.addEventListener('keydown', function (e) { if (e.key === 'Escape') { setOpen(false); toggle.focus(); } });
02. Tabs (No JavaScript)
Pure CSS
Three tabs switched with hidden radio buttons and the :checked selector, so they work without JavaScript and arrow keys move between them. The active tab gets an underline and stronger text. For complex apps, add the full ARIA tabs pattern with JavaScript; for simple content panels this is enough.
View code
<div class="ttn-tabs">
<input type="radio" name="ttn-tab" id="ttn-t1" checked>
<label for="ttn-t1">Details</label>
<input type="radio" name="ttn-tab" id="ttn-t2">
<label for="ttn-t2">Shipping</label>
<input type="radio" name="ttn-tab" id="ttn-t3">
<label for="ttn-t3">Returns</label>
<div class="ttn-panel" id="ttn-p1">Solid oak, oiled finish. 40 × 30 × 12 cm.</div>
<div class="ttn-panel" id="ttn-p2">Ships in 2 working days. Free over $80.</div>
<div class="ttn-panel" id="ttn-p3">Return within 30 days for a full refund.</div>
</div>
An FAQ accordion built on the native details and summary elements, which are keyboard accessible and announced correctly by screen readers with no JavaScript. The plus sign rotates into a cross when a panel opens. Adding the same name attribute to each details element makes only one open at a time in current browsers.
View code
<div class="ttn-acc">
<details name="ttn-faq" open>
<summary>How long does delivery take?</summary>
<p>Most orders arrive in two to four working days.</p>
</details>
<details name="ttn-faq">
<summary>Can I return an item?</summary>
<p>Yes, within 30 days, as long as it is unused.</p>
</details>
<details name="ttn-faq">
<summary>Do you ship abroad?</summary>
<p>We ship to most countries. Costs are shown at checkout.</p>
</details>
</div>
A breadcrumb trail inside a nav element with an ordered list, the structure search engines and screen readers expect. Separators are drawn with CSS so they are not read aloud, the current page is marked with aria-current, and long trails wrap onto two lines instead of overflowing.
Page links with previous and next controls, a current page marker and an ellipsis for skipped pages. Every control is at least 40px square for touch, the current page uses aria-current so it is announced, and disabled controls are real disabled states rather than just greyed-out text.
An app or docs sidebar with grouped links, icons drawn in CSS, a count badge and a clear active state. Section headings are real headings so screen-reader users can jump between groups, and the active link uses aria-current plus a visible bar, not colour alone.
Links sit in a row on wide containers and collapse behind a Menu button on narrow ones, opening as a vertical list below the bar. The breakpoint is a container query, so the navbar responds to the space it is given, not the window.
var b = document.querySelector('.rn1 .mb'), l = document.getElementById('rn1l');
b.onclick = function () { var o = l.classList.toggle('open'); b.setAttribute('aria-expanded', o); };
08. Priority Plus: Overflow into More
ResponsivePriority plus
Links that fit stay visible and the rest move into a More menu, so the most important links never disappear behind a hamburger. A ResizeObserver measures the bar and moves list items between the two lists in source order.
var nav = document.querySelector('.rn2 nav'), vis = nav.querySelector('.vis'), more = nav.querySelector('.more'), mb = more.querySelector('button'), list = document.getElementById('rn2m');
function fit() {
while (list.firstElementChild) vis.appendChild(list.firstElementChild);
more.hidden = true;
if (vis.scrollWidth <= vis.clientWidth) return;
more.hidden = false;
while (vis.scrollWidth > vis.clientWidth && vis.lastElementChild) list.insertBefore(vis.lastElementChild, list.firstChild);
}
mb.onclick = function () { var o = mb.getAttribute('aria-expanded') !== 'true'; mb.setAttribute('aria-expanded', o); list.hidden = !o; };
new ResizeObserver(fit).observe(nav);
09. Scrollable Link Row with Fades
ResponsiveScroll
On narrow screens the links stay in one row that scrolls sideways, with faded edges hinting that there is more, the pattern news and shop sites use for categories. The fade is a mask on the list, and the row is a labelled navigation landmark.
The menu button opens a full-screen overlay with large links, built on a modal dialog so focus is trapped inside it, the page behind is inert and Escape closes it. The overlay fades in with @starting-style.
var d = document.querySelector('.rn4 dialog');
document.querySelector('.rn4 .open').onclick = function () { d.showModal(); };
d.querySelector('.close').onclick = function () { d.close(); };
d.querySelectorAll('nav a').forEach(function (a) { a.onclick = function () { d.close(); }; });
11. Logo Above Links on Mobile
ResponsiveCentred
Some sites have few enough links that no hamburger is needed: on narrow containers the logo sits centred above a wrapping row of links, on wide ones it moves to the left. Every link stays visible at every size, which is the most usable option of all.
View code
<div class="rn5"><nav aria-label="Main"><a class="logo" href="#home">Olive & Oak</a><ul><li><a href="#menu">Menu</a></li><li><a href="#book">Book</a></li><li><a href="#visit">Visit</a></li></ul></nav></div>
A collapsible menu that needs no script at all: the menu is a details element whose summary is the Menu button, and on wide containers a container query hides the summary and shows the links as a row. It works even before JavaScript loads.
The menu slides in from the left as a modal drawer over a dimmed page. The native dialog element handles focus trapping and Escape, the slide is a transform transition with @starting-style, and clicking the dimmed backdrop closes it.
var d = document.querySelector('.rn7 dialog');
document.querySelector('.rn7 .open').onclick = function () { d.showModal(); };
d.querySelector('.close').onclick = function () { d.close(); };
d.addEventListener('click', function (e) { if (e.target === d) d.close(); });
14. Sticky Navbar in a Scrolling Page
StickyNavbar
A navbar that stays at the top as the page scrolls, with position: sticky; top: 0 and a solid background so content does not show through. Because sticky stays in the flow, there is no gap or jump when it starts sticking.
The navbar slides away when you scroll down to read and comes back the moment you scroll up, saving space on small screens. A scroll listener compares positions; the bar never hides while anything inside it has keyboard focus.
View code
<div class="snb2" tabindex="0" role="region" aria-label="Article, scroll"><nav aria-label="Main"><a href="#home">Journal</a><a href="#subscribe">Subscribe</a></nav><article><p>Scroll down and the bar hides.</p><p>Scroll up a little and it returns.</p><p>Reading space matters on phones.</p><p>Keep scrolling.</p><p>Almost there.</p><p>The end.</p></article></div>
var box = document.querySelector('.snb2'), nav = box.querySelector('nav'), last = 0;
box.addEventListener('scroll', function () { var y = box.scrollTop; if (!nav.contains(document.activeElement)) box.classList.toggle('up', y > last && y > 60); last = y; }, { passive: true });
16. Navbar That Shrinks When Scrolled
StickyShrink
A tall header with a large logo becomes a slim bar once you scroll past the top. A class toggled by an IntersectionObserver sentinel changes the padding and logo size, and transform keeps the logo shrink smooth.
var box = document.querySelector('.snb3');
new IntersectionObserver(function (es) { box.classList.toggle('small', !es[0].isIntersecting); }, { root: box }).observe(box.querySelector('.sent'));
17. Translucent Blurred Navbar
StickyGlass
A sticky bar with a semi-transparent background and backdrop-filter: blur, so colourful content passes underneath as a soft blur. The background stays opaque enough on its own for the links to keep contrast if blur is unsupported.
The sticky nav highlights the link for the section currently in view and moves aria-current with it, so the highlight and the announced state agree. An IntersectionObserver with a band in the middle of the view picks the active section.
View code
<div class="snb5" tabindex="0" role="region" aria-label="Guide, scroll"><nav aria-label="On this page"><a href="#snb5a" aria-current="true">Plan</a><a href="#snb5b">Build</a><a href="#snb5c">Launch</a></nav><section id="snb5a"><h3>Plan</h3><p>Define the goal.</p></section><section id="snb5b"><h3>Build</h3><p>Make the first version.</p></section><section id="snb5c"><h3>Launch</h3><p>Ship and measure.</p></section></div>
var box = document.querySelector('.snb5'), links = box.querySelectorAll('nav a');
var io = new IntersectionObserver(function (es) { es.forEach(function (e) { if (!e.isIntersecting) return; links.forEach(function (l) { if (l.getAttribute('href') === '#' + e.target.id) l.setAttribute('aria-current', 'true'); else l.removeAttribute('aria-current'); }); }); }, { root: box, rootMargin: '-40% 0px -55% 0px' });
box.querySelectorAll('section').forEach(function (s) { io.observe(s); });
links.forEach(function (l) { l.onclick = function (e) { e.preventDefault(); var s = box.querySelector(l.getAttribute('href')); box.scrollTo({ top: s.offsetTop - 50, behavior: 'smooth' }); }; });
19. Sticky Bottom Tab Bar
StickyMobile
A mobile app tab bar that sticks to the bottom of the screen, with icons above short labels. Labels are always visible, because icon-only tab bars are harder to learn, and the bar includes safe-area padding for phones with a home indicator.
A thin utility bar (phone number, language) scrolls away normally while the main navigation below it sticks. Only the second element is sticky, which is all it takes, so the page keeps its main links without wasting space on the utilities.
A navbar over colourful shapes with backdrop-filter: blur and a translucent white fill, the classic frosted glass. A thin light border on the top edge sells the glass edge, and the fill is strong enough that the links pass contrast even where blur is unsupported.
A compact navbar that floats as a rounded pill, centred over the page with a little gap from the top. The glass tint is a light white with a soft shadow, a look that suits light, photo-heavy pages.
The liquid glass look: a heavier blur, a bright specular highlight along the top edge, an inner glow and a subtle refraction-like gradient border. It is all layered box-shadows and a masked gradient border, with no images or SVG filters.
Glass does not have to be white: a dark smoked tint over a bright photo gives strong contrast for white links and a more serious tone. The tint is rgba black at 55 percent, which keeps the links readable on the lightest part of any image.
The dropdown under a glass navbar should be glass too, or it looks pasted on. Both share the same tint, blur and border tokens through custom properties, and the dropdown is a disclosure button with aria-expanded.
var b = document.querySelector('.gn5 button'), m = document.getElementById('gn5m');
b.onclick = function () { var o = b.getAttribute('aria-expanded') !== 'true'; b.setAttribute('aria-expanded', o); m.hidden = !o; };
document.addEventListener('keydown', function (e) { if (e.key === 'Escape' && !m.hidden) { b.click(); b.focus(); } });
26. Glass Dock with Hover Lift
GlassDock
A desktop-style dock of app icons on a glass shelf at the bottom, where the hovered or focused icon lifts and grows. Each icon is a link with a name, and a small dot under the current app marks it with aria-current as well.
A segmented control on glass where a brighter pill slides behind the selected item. The items are links with aria-current, the pill is a single element moved with transform, and its position is computed from the current link's box.
var nav = document.querySelector('.gn7 nav'), pill = nav.querySelector('.pill'), links = nav.querySelectorAll('a');
function to(a) { pill.style.width = a.offsetWidth + 'px'; pill.style.transform = 'translateX(' + a.offsetLeft + 'px)'; }
links.forEach(function (a) { a.onclick = function (e) { e.preventDefault(); links.forEach(function (x) { if (x === a) x.setAttribute('aria-current', 'page'); else x.removeAttribute('aria-current'); }); to(a); }; });
to(nav.querySelector('[aria-current]'));
28. Tab Bar with Centre Action
MobileTab bar
A five-slot bottom tab bar with a raised round button in the middle for the main action, such as posting. Every tab keeps a text label, the centre button has an accessible name, and the bar sits in a phone-shaped frame here.
On phones the menu opens as a sheet sliding up from the bottom, where thumbs can reach every item. It is a modal dialog, so focus stays inside and Escape or the Close button dismisses it, and the sheet's slide is a transform with @starting-style.
var d = document.querySelector('.mn2 dialog');
document.querySelector('.mn2 .open').onclick = function () { d.showModal(); };
d.querySelector('.close').onclick = function () { d.close(); };
30. Full-Screen Menu with Big Links
MobileFull screen
A mobile menu panel that fills the frame with large, well-spaced links and secondary links at the bottom. Large type makes the menu fast to scan and easy to tap, and the current page is marked with aria-current and an arrow.
Top tabs that scroll sideways when there are more than fit, with the selected tab underlined and scrolled into view when chosen. It uses the ARIA tabs pattern, so left and right arrows move between tabs on a keyboard.
var tabs = document.querySelectorAll('.mn4 [role=tab]'), p = document.getElementById('mn4p');
function sel(i) { tabs.forEach(function (x, j) { x.setAttribute('aria-selected', i === j); x.tabIndex = i === j ? 0 : -1; }); p.textContent = tabs[i].textContent + ' posts.'; p.setAttribute('aria-label', tabs[i].textContent); tabs[i].focus(); tabs[i].scrollIntoView({ block: 'nearest', inline: 'center', behavior: 'smooth' }); }
tabs.forEach(function (t, i) { t.onclick = function () { sel(i); }; t.onkeydown = function (e) { var k = { ArrowRight: 1, ArrowLeft: -1 }[e.key]; if (k) { e.preventDefault(); sel((i + k + tabs.length) % tabs.length); } }; });
32. Back Header with Title and Action
MobileHeader
The header of a detail screen in a mobile web app: a back link on the left, the screen title centred and a single action on the right. The title is the page heading, and the back link names its destination rather than just saying Back.
View code
<header class="mn5"><a href="#orders" aria-label="Back to Orders"><span aria-hidden="true">‹</span> Orders</a><h3>Order #1042</h3><button>Share</button></header>
The iOS-style segmented control for switching views, built from radio buttons so only one segment can be on and arrow keys move between them. The selected segment's raised look comes from :has(:checked) on its label.
A bottom navigation that floats as a dark pill above the content, with the current item expanding to show its label while the others show only icons with hidden labels. The expanding label is a width transition on a span.
var links = document.querySelectorAll('.mn7 a');
links.forEach(function (a) { a.onclick = function (e) { e.preventDefault(); links.forEach(function (x) { if (x === a) x.setAttribute('aria-current', 'page'); else x.removeAttribute('aria-current'); }); }; });
35. Hamburger to Cross
MenuAnimation
The classic three-line icon that morphs into an X when the menu opens. The middle bar fades out while the outer bars rotate into a cross, the button toggles aria-expanded, and its accessible name stays Menu in both states.
A variation where the three lines become a left-pointing arrow, useful when opening a menu means navigating back. The top and bottom bars shorten and rotate towards the left end of the middle bar, all with transforms.
Pairing the icon with the word Menu makes it clearer for people who do not recognise the three-line symbol. The visible text doubles as the accessible name, and the label changes to Close when the menu is open.
A complete mobile header: the hamburger opens a panel that slides in from the left. The button controls the panel with aria-controls and aria-expanded, Escape closes the panel and returns focus to the button, and the links are a normal list.
const mb = document.querySelector('.mb'), panel = document.getElementById('mnav');
function set(open) {
mb.setAttribute('aria-expanded', String(open));
panel.classList.toggle('open', open);
if (open) panel.querySelector('a').focus();
}
mb.addEventListener('click', () => set(mb.getAttribute('aria-expanded') !== 'true'));
document.addEventListener('keydown', e => { if (e.key === 'Escape' && panel.classList.contains('open')) { set(false); mb.focus(); } });
39. Full-Screen Overlay Menu
MenuOverlay
A bold full-screen menu for portfolio and agency sites: large links fade in one after another over a dark overlay. The stagger uses a custom property per item for its delay, and the overlay is hidden from the keyboard until it opens.
const fb = document.querySelector('.fsb'), fm = document.getElementById('fsm');
fb.addEventListener('click', () => {
const open = !fm.classList.contains('open');
fm.classList.toggle('open', open);
fb.setAttribute('aria-expanded', String(open));
fb.textContent = open ? 'Close' : 'Menu';
});
40. Kebab and Meatball Icons
IconOverflow
Overflow menu triggers drawn entirely in CSS: three vertical dots (kebab) and three horizontal dots (meatball), made from one dot plus two box-shadow copies. Each is a real button with an accessible name such as More options.
The bars first squeeze together into a single line, then rotate into an X, a two-stage motion made with transition delays that run in reverse when closing. It feels more mechanical and deliberate than a straight rotation.
A compact menu that drops down below the button instead of sliding in, suited to simple sites with four or five pages. Clicking outside closes it, Escape closes it and returns focus, and the open list is a normal set of links.
const db = document.querySelector('.ddb'), dl = document.getElementById('ddl');
function setOpen(o) { dl.hidden = !o; db.setAttribute('aria-expanded', String(o)); }
db.addEventListener('click', () => setOpen(dl.hidden));
document.addEventListener('click', e => { if (!e.target.closest('.dd')) setOpen(false); });
document.addEventListener('keydown', e => { if (e.key === 'Escape' && !dl.hidden) { setOpen(false); db.focus(); } });
About these CSS Navigation
Navigation must be accessible first
Navigation is how people move through a site, so a broken menu breaks the whole visit. Use real links and buttons, mark the current page with aria-current="page", give the navigation a label such as aria-label="Main", and make sure every control is reachable with the Tab key and shows a visible focus ring.
Mobile menus need a real button
The menu toggle in the navbar demo is a <button> with aria-expanded and aria-controls, so assistive technology announces whether the menu is open. The Escape key closes it and returns focus to the button, which is what keyboard users expect from any pop-up.
Use native elements where they exist
The accordion uses <details> and <summary>, which browsers already make keyboard accessible and announce correctly, with no JavaScript. Native elements are less code to maintain and often more robust than custom widgets.
Breadcrumbs and pagination help search engines too
Breadcrumbs inside a nav with an ordered list, and pagination with real links, give search engines a clear map of your site's structure. Pair breadcrumbs with BreadcrumbList structured data for the best chance of rich results.
Frequently asked questions
Are the CSS-only tabs accessible?
They work with the keyboard and are fine for simple content panels. For complex applications, add the full ARIA tabs pattern with JavaScript so screen readers announce tab and panel roles.
How do I make only one accordion item open?
Give every details element the same name attribute. Current browsers then close the others when one opens, with no script.
Do these work on mobile?
Yes. Every control has a touch target of at least 40px, and the navbar collapses into a menu below 600px.