Bottom Navigation
A thumb-reachable bar of 3–5 destinations with a sliding active indicator.
AI prompt
Build a mobile bottom navigation bar with four tabs: Home, Search, Saved and Profile. Each tab is a button with an inline SVG icon (24px) above a 12px label. The bar is 64px tall, uses a white surface colour with a 1px top border, and the four tabs share the width equally. Add one rounded pill (56x32px, the accent colour at 10% opacity) behind the active icon. When a tab is selected, the pill slides to it using a CSS custom property --i and transform: translateX, 350ms, cubic-bezier(0.3,1.4,0.5,1). The active tab uses the accent colour and aria-current="page". Pressing a tab scales its icon to 0.92. Support keyboard arrows, Home and End, with focus-visible outlines. Update a screen title above the bar when the tab changes. Respect prefers-reduced-motion by removing the overshoot and the scale. Add padding-bottom: env(safe-area-inset-bottom). No libraries.About this pattern
Definition
A fixed bar at the bottom of a mobile screen that holds three to five top-level destinations. Each destination is an icon with a short label. The active destination is marked by colour and a pill that slides between tabs.
Purpose & UX principles
- Puts the most-used destinations inside the thumb zone, where one-handed reach is easiest.
- Keeps the user's position visible at all times, so they never have to guess where they are.
- Limit it to five items; more than that makes touch targets too small and labels collide.
- Always show text labels. Icon-only bars are slower to learn.
Interaction states
- Default: muted icon and label.
- Active: accent colour, the pill sits behind the icon,
aria-current="page". - Pressed: icon scales to 0.92.
- Focus-visible: 2px accent outline around the tab.
- Keyboard: Left and Right arrows move between tabs, Home and End jump to the first and last.
Motion specification
- Pill slide: transform translateX, 350ms, cubic-bezier(0.3, 1.4, 0.5, 1) for a slight overshoot.
- Icon press: scale 0.92, 120ms ease-out.
- Content change: 160ms fade of the screen title.
- Reduced motion: the pill jumps without overshoot, no scaling.
Responsive behaviour
- Phones (under 600px): full-width bar fixed to the bottom, items share the width equally.
- Tablets and desktops: move these destinations to a side rail or top navigation instead; a bottom bar on a wide screen is far from the cursor.
- Respect the safe-area inset at the bottom (
env(safe-area-inset-bottom)) so the bar clears the home indicator.
Code
<div class="phone">
<main class="screen"><p class="eyebrow">Current tab</p><h2 id="title">Home</h2><p>Tap a tab, or focus the bar and use the arrow keys.</p></main>
<nav class="bnav" aria-label="Primary">
<span class="pill" aria-hidden="true"></span>
<button class="tab" aria-current="page" data-t="Home"><svg viewBox="0 0 24 24"><path d="M3 11l9-8 9 8v10h-6v-6H9v6H3z"/></svg><span>Home</span></button>
<button class="tab" data-t="Search"><svg viewBox="0 0 24 24"><path d="M10 4a6 6 0 104.5 10l5 5 1.5-1.5-5-5A6 6 0 0010 4z"/></svg><span>Search</span></button>
<button class="tab" data-t="Saved"><svg viewBox="0 0 24 24"><path d="M12 21s-8-5.2-8-11a4.5 4.5 0 018-2.8A4.5 4.5 0 0120 10c0 5.8-8 11-8 11z"/></svg><span>Saved</span></button>
<button class="tab" data-t="Profile"><svg viewBox="0 0 24 24"><path d="M12 12a4 4 0 100-8 4 4 0 000 8zm-8 9a8 8 0 0116 0z"/></svg><span>Profile</span></button>
</nav>
</div>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
.phone{width:min(340px,100%);height:520px;display:flex;flex-direction:column;border:1px solid var(--line);border-radius:28px;background:var(--surface);overflow:hidden}
.screen{flex:1;padding:28px 24px}
.eyebrow{font-size:11px;letter-spacing:.14em;text-transform:uppercase;color:var(--muted)}
.screen h2{font-size:30px;margin:6px 0 10px}
.screen p{color:var(--muted)}
.bnav{position:relative;display:grid;grid-template-columns:repeat(4,1fr);height:64px;border-top:1px solid var(--line);background:var(--surface-2);padding-bottom:env(safe-area-inset-bottom);--i:0}
.pill{position:absolute;top:8px;left:calc(12.5% - 28px);width:56px;height:32px;border-radius:99px;background:color-mix(in srgb,var(--accent) 10%,transparent);transform:translateX(0);transition:transform .35s cubic-bezier(.3,1.4,.5,1)}
.tab{position:relative;z-index:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;color:var(--muted);background:none;border:0;font:inherit;font-size:12px;cursor:pointer}
.tab svg{width:24px;height:24px;fill:currentColor;transition:transform .12s ease-out}
.tab:active svg{transform:scale(.92)}
.tab[aria-current=page]{color:var(--accent)}
.tab:focus-visible{outline:2px solid var(--accent);outline-offset:-4px;border-radius:12px}
@media (prefers-reduced-motion:reduce){.pill{transition:none}.tab svg{transition:none}}const nav=document.querySelector('.bnav'),tabs=[...nav.querySelectorAll('.tab')],title=document.getElementById('title');
function select(i){
tabs.forEach((t,k)=>k===i?t.setAttribute('aria-current','page'):t.removeAttribute('aria-current'));
nav.style.setProperty('--i',i);
const pill=nav.querySelector('.pill');pill.style.transform='translateX('+(i*nav.clientWidth/tabs.length)+'px)';
title.textContent=tabs[i].dataset.t;tabs[i].focus({preventScroll:true});
}
tabs.forEach((t,i)=>t.addEventListener('click',()=>select(i)));
nav.addEventListener('keydown',e=>{
const i=tabs.indexOf(document.activeElement);if(i<0)return;
const map={ArrowRight:(i+1)%tabs.length,ArrowLeft:(i-1+tabs.length)%tabs.length,Home:0,End:tabs.length-1};
if(e.key in map){e.preventDefault();select(map[e.key]);}
});One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Bottom Navigation — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
.phone{width:min(340px,100%);height:520px;display:flex;flex-direction:column;border:1px solid var(--line);border-radius:28px;background:var(--surface);overflow:hidden}
.screen{flex:1;padding:28px 24px}
.eyebrow{font-size:11px;letter-spacing:.14em;text-transform:uppercase;color:var(--muted)}
.screen h2{font-size:30px;margin:6px 0 10px}
.screen p{color:var(--muted)}
.bnav{position:relative;display:grid;grid-template-columns:repeat(4,1fr);height:64px;border-top:1px solid var(--line);background:var(--surface-2);padding-bottom:env(safe-area-inset-bottom);--i:0}
.pill{position:absolute;top:8px;left:calc(12.5% - 28px);width:56px;height:32px;border-radius:99px;background:color-mix(in srgb,var(--accent) 10%,transparent);transform:translateX(0);transition:transform .35s cubic-bezier(.3,1.4,.5,1)}
.tab{position:relative;z-index:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;color:var(--muted);background:none;border:0;font:inherit;font-size:12px;cursor:pointer}
.tab svg{width:24px;height:24px;fill:currentColor;transition:transform .12s ease-out}
.tab:active svg{transform:scale(.92)}
.tab[aria-current=page]{color:var(--accent)}
.tab:focus-visible{outline:2px solid var(--accent);outline-offset:-4px;border-radius:12px}
@media (prefers-reduced-motion:reduce){.pill{transition:none}.tab svg{transition:none}}
</style></head>
<body><div class="stage">
<div class="phone">
<main class="screen"><p class="eyebrow">Current tab</p><h2 id="title">Home</h2><p>Tap a tab, or focus the bar and use the arrow keys.</p></main>
<nav class="bnav" aria-label="Primary">
<span class="pill" aria-hidden="true"></span>
<button class="tab" aria-current="page" data-t="Home"><svg viewBox="0 0 24 24"><path d="M3 11l9-8 9 8v10h-6v-6H9v6H3z"/></svg><span>Home</span></button>
<button class="tab" data-t="Search"><svg viewBox="0 0 24 24"><path d="M10 4a6 6 0 104.5 10l5 5 1.5-1.5-5-5A6 6 0 0010 4z"/></svg><span>Search</span></button>
<button class="tab" data-t="Saved"><svg viewBox="0 0 24 24"><path d="M12 21s-8-5.2-8-11a4.5 4.5 0 018-2.8A4.5 4.5 0 0120 10c0 5.8-8 11-8 11z"/></svg><span>Saved</span></button>
<button class="tab" data-t="Profile"><svg viewBox="0 0 24 24"><path d="M12 12a4 4 0 100-8 4 4 0 000 8zm-8 9a8 8 0 0116 0z"/></svg><span>Profile</span></button>
</nav>
</div>
</div>
<script>
const nav=document.querySelector('.bnav'),tabs=[...nav.querySelectorAll('.tab')],title=document.getElementById('title');
function select(i){
tabs.forEach((t,k)=>k===i?t.setAttribute('aria-current','page'):t.removeAttribute('aria-current'));
nav.style.setProperty('--i',i);
const pill=nav.querySelector('.pill');pill.style.transform='translateX('+(i*nav.clientWidth/tabs.length)+'px)';
title.textContent=tabs[i].dataset.t;tabs[i].focus({preventScroll:true});
}
tabs.forEach((t,i)=>t.addEventListener('click',()=>select(i)));
nav.addEventListener('keydown',e=>{
const i=tabs.indexOf(document.activeElement);if(i<0)return;
const map={ArrowRight:(i+1)%tabs.length,ArrowLeft:(i-1+tabs.length)%tabs.length,Home:0,End:tabs.length-1};
if(e.key in map){e.preventDefault();select(map[e.key]);}
});
</script>
</body></html>