Floating Navigation
A detached pill-shaped dock whose icons grow toward the pointer.
AI prompt
Build a floating dock navigation centred at the bottom of a 520px demo area, with 24px side margins, rounded 22px, a translucent surface with backdrop blur and a 1px border. It contains five icon buttons (44px) with tooltips: Home, Explore, Create, Alerts, Profile. On devices with hover, icons scale up to 1.5x as the pointer gets within 90px horizontally, using a cosine falloff computed in a pointermove handler and applied through a CSS variable --s on each button; reset smoothly with a 200ms transition when the pointer leaves. Keep the layout stable by aligning icons to the bottom so they grow upward. Show a small dot under the current item with aria-current="page". Disable scaling for pointer: coarse and for prefers-reduced-motion. Keyboard focus shows a 2px accent ring.About this pattern
Definition
A compact navigation bar that floats above the content with a margin on every side instead of touching the screen edge. In this version icons enlarge smoothly as the pointer approaches, in the style of a desktop dock.
Purpose & UX principles
- Frees the edges of the screen and feels lightweight, which suits portfolios, media apps and tools with a few destinations.
- Proximity scaling makes small targets easier to hit and gives immediate feedback.
- Because it floats over content, it needs a solid or blurred background to stay readable.
Interaction states
- Idle: icons at 44px.
- Pointer nearby: scale up to 1.5x with falloff over about 90px.
- Current: small dot under the icon and
aria-current="page". - Focus-visible: ring around the icon.
Motion specification
- Scale is computed per frame from pointer distance, with a smooth cosine falloff.
- Return to idle: 200ms ease-out when the pointer leaves.
- Reduced motion: no scaling.
Responsive behaviour
- Touch devices have no hover, so disable the magnify effect and keep icons at a constant 44px.
- Keep the dock centred and no wider than the viewport minus 24px.
Code
<div class="area"><p class="hint">Move the pointer over the dock</p>
<nav class="dock" id="dock" aria-label="Dock">
<button class="d" aria-current="page" aria-label="Home" title="Home">⌂</button>
<button class="d" aria-label="Explore" title="Explore">✦</button>
<button class="d" aria-label="Create" title="Create">+</button>
<button class="d" aria-label="Alerts" title="Alerts">♪</button>
<button class="d" aria-label="Profile" title="Profile">☺</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}
.area{position:relative;width:min(520px,100%);height:300px;border:1px solid var(--line);border-radius:18px;background:var(--surface);overflow:hidden}
.hint{text-align:center;color:var(--muted);margin-top:40px;font-size:14px}
.dock{position:absolute;left:50%;bottom:20px;transform:translateX(-50%);display:flex;align-items:flex-end;gap:8px;padding:8px 12px;border-radius:22px;background:rgba(255,255,255,.75);backdrop-filter:blur(14px);border:1px solid var(--line)}
.d{--s:1;position:relative;width:44px;height:44px;border-radius:14px;border:0;background:var(--surface-2);color:var(--text);font-size:20px;cursor:pointer;transform:scale(var(--s));transform-origin:bottom center;transition:transform .2s ease-out}
.d.live{transition:none}
.d[aria-current=page]::after{content:"";position:absolute;left:50%;bottom:-7px;width:4px;height:4px;margin-left:-2px;border-radius:50%;background:var(--accent)}
.d:focus-visible{outline:2px solid var(--accent);outline-offset:3px}
@media (hover:none),(prefers-reduced-motion:reduce){.d{transform:none!important;transition:none}}const dock=document.getElementById('dock'),btns=[...dock.children];
const fine=matchMedia('(hover:hover)').matches&&!matchMedia('(prefers-reduced-motion:reduce)').matches;
if(fine){
dock.addEventListener('pointermove',e=>{btns.forEach(b=>{const r=b.getBoundingClientRect(),d=Math.abs(e.clientX-(r.left+r.width/2));
const t=Math.max(0,1-d/90);b.classList.add('live');b.style.setProperty('--s',(1+0.5*(0.5-0.5*Math.cos(Math.PI*t))).toFixed(3));});});
dock.addEventListener('pointerleave',()=>btns.forEach(b=>{b.classList.remove('live');b.style.setProperty('--s',1);}));
}
btns.forEach(b=>b.addEventListener('click',()=>{btns.forEach(x=>x.removeAttribute('aria-current'));b.setAttribute('aria-current','page');}));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>Floating 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}}
.area{position:relative;width:min(520px,100%);height:300px;border:1px solid var(--line);border-radius:18px;background:var(--surface);overflow:hidden}
.hint{text-align:center;color:var(--muted);margin-top:40px;font-size:14px}
.dock{position:absolute;left:50%;bottom:20px;transform:translateX(-50%);display:flex;align-items:flex-end;gap:8px;padding:8px 12px;border-radius:22px;background:rgba(255,255,255,.75);backdrop-filter:blur(14px);border:1px solid var(--line)}
.d{--s:1;position:relative;width:44px;height:44px;border-radius:14px;border:0;background:var(--surface-2);color:var(--text);font-size:20px;cursor:pointer;transform:scale(var(--s));transform-origin:bottom center;transition:transform .2s ease-out}
.d.live{transition:none}
.d[aria-current=page]::after{content:"";position:absolute;left:50%;bottom:-7px;width:4px;height:4px;margin-left:-2px;border-radius:50%;background:var(--accent)}
.d:focus-visible{outline:2px solid var(--accent);outline-offset:3px}
@media (hover:none),(prefers-reduced-motion:reduce){.d{transform:none!important;transition:none}}
</style></head>
<body><div class="stage">
<div class="area"><p class="hint">Move the pointer over the dock</p>
<nav class="dock" id="dock" aria-label="Dock">
<button class="d" aria-current="page" aria-label="Home" title="Home">⌂</button>
<button class="d" aria-label="Explore" title="Explore">✦</button>
<button class="d" aria-label="Create" title="Create">+</button>
<button class="d" aria-label="Alerts" title="Alerts">♪</button>
<button class="d" aria-label="Profile" title="Profile">☺</button>
</nav></div>
</div>
<script>
const dock=document.getElementById('dock'),btns=[...dock.children];
const fine=matchMedia('(hover:hover)').matches&&!matchMedia('(prefers-reduced-motion:reduce)').matches;
if(fine){
dock.addEventListener('pointermove',e=>{btns.forEach(b=>{const r=b.getBoundingClientRect(),d=Math.abs(e.clientX-(r.left+r.width/2));
const t=Math.max(0,1-d/90);b.classList.add('live');b.style.setProperty('--s',(1+0.5*(0.5-0.5*Math.cos(Math.PI*t))).toFixed(3));});});
dock.addEventListener('pointerleave',()=>btns.forEach(b=>{b.classList.remove('live');b.style.setProperty('--s',1);}));
}
btns.forEach(b=>b.addEventListener('click',()=>{btns.forEach(x=>x.removeAttribute('aria-current'));b.setAttribute('aria-current','page');}));
</script>
</body></html>