Icon Button
A square icon-only button with an accessible name, tooltip and toggle state.
AI prompt
Create three icon buttons (Like, Bookmark, Share), each 44x44px with a 24px inline SVG. Each has an aria-label and a tooltip shown on hover and keyboard focus (small dark label above the button, 140ms fade). Like and Bookmark are toggles using aria-pressed: when on, the icon fills with the accent colour and plays a 280ms pop animation (scale 1, 1.25, 1) with cubic-bezier(0.3,1.6,0.5,1). Hover shows a circular surface behind the icon. Pressing scales the icon to 0.9. Share is a plain action button that changes its tooltip to "Copied" for 1.2 seconds. Focus-visible shows a 2px ring. Remove the pop animation under prefers-reduced-motion.About this pattern
Definition
A button that shows only an icon. The icon sits inside a generous hit area, has an accessible name supplied by aria-label, and optionally acts as a toggle (like, bookmark, mute) reported through aria-pressed.
Purpose & UX principles
- Saves space for familiar, repeated actions such as like, share or close.
- The icon alone is not a label: provide
aria-labeland a tooltip for sighted users who are unsure. - Use filled icon plus colour change for the on state so that state is not communicated by colour alone.
Interaction states
- Default, hover (circular surface appears), pressed (scale 0.9), focus-visible ring.
- Toggled on: filled icon, accent colour,
aria-pressed="true". - Toggling plays a small pop on the icon.
Motion specification
- Hover surface: 140ms fade.
- Pop on toggle: scale 1 → 1.25 → 1 in 280ms with spring-like easing.
- Reduced motion: no pop, only the colour change.
Responsive behaviour
- Visual size 24px, hit area at least 44×44px.
- Tooltips appear on hover and focus only; on touch devices rely on the accessible name and clear iconography.
Code
<div class="row">
<button class="ib" aria-label="Like" aria-pressed="false" data-tip="Like"><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></button>
<button class="ib" aria-label="Bookmark" aria-pressed="false" data-tip="Bookmark"><svg viewBox="0 0 24 24"><path d="M6 3h12v18l-6-4-6 4z"/></svg></button>
<button class="ib" id="share" aria-label="Share" data-tip="Share"><svg viewBox="0 0 24 24"><path d="M12 3l5 5-1.4 1.4L13 6.8V16h-2V6.8L8.4 9.4 7 8zM5 14h2v5h10v-5h2v7H5z"/></svg></button>
</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}
.row{display:flex;gap:10px}
.ib{position:relative;width:44px;height:44px;display:grid;place-items:center;border:0;border-radius:50%;background:transparent;color:var(--muted);cursor:pointer;transition:background .14s,color .14s}
.ib svg{width:24px;height:24px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linejoin:round;transition:transform .09s}
.ib:hover{background:var(--surface-2);color:var(--text)}
.ib:active svg{transform:scale(.9)}
.ib:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.ib[aria-pressed=true]{color:var(--accent)}
.ib[aria-pressed=true] svg{fill:currentColor}
.ib.pop svg{animation:pop .28s cubic-bezier(.3,1.6,.5,1)}
@keyframes pop{50%{transform:scale(1.25)}}
.ib::after{content:attr(data-tip);position:absolute;bottom:calc(100% + 6px);left:50%;transform:translateX(-50%);background:var(--text);color:var(--bg);font-size:12px;font-weight:600;padding:4px 9px;border-radius:7px;white-space:nowrap;opacity:0;pointer-events:none;transition:opacity .14s}
.ib:hover::after,.ib:focus-visible::after{opacity:1}
@media (prefers-reduced-motion:reduce){.ib.pop svg{animation:none}.ib,.ib svg{transition:none}}document.querySelectorAll('.ib[aria-pressed]').forEach(b=>b.addEventListener('click',()=>{
const on=b.getAttribute('aria-pressed')!=='true';b.setAttribute('aria-pressed',on);
b.classList.remove('pop');void b.offsetWidth;if(on)b.classList.add('pop');
}));
const share=document.getElementById('share');
share.addEventListener('click',()=>{share.dataset.tip='Copied';setTimeout(()=>share.dataset.tip='Share',1200);});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>Icon Button — 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}}
.row{display:flex;gap:10px}
.ib{position:relative;width:44px;height:44px;display:grid;place-items:center;border:0;border-radius:50%;background:transparent;color:var(--muted);cursor:pointer;transition:background .14s,color .14s}
.ib svg{width:24px;height:24px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linejoin:round;transition:transform .09s}
.ib:hover{background:var(--surface-2);color:var(--text)}
.ib:active svg{transform:scale(.9)}
.ib:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.ib[aria-pressed=true]{color:var(--accent)}
.ib[aria-pressed=true] svg{fill:currentColor}
.ib.pop svg{animation:pop .28s cubic-bezier(.3,1.6,.5,1)}
@keyframes pop{50%{transform:scale(1.25)}}
.ib::after{content:attr(data-tip);position:absolute;bottom:calc(100% + 6px);left:50%;transform:translateX(-50%);background:var(--text);color:var(--bg);font-size:12px;font-weight:600;padding:4px 9px;border-radius:7px;white-space:nowrap;opacity:0;pointer-events:none;transition:opacity .14s}
.ib:hover::after,.ib:focus-visible::after{opacity:1}
@media (prefers-reduced-motion:reduce){.ib.pop svg{animation:none}.ib,.ib svg{transition:none}}
</style></head>
<body><div class="stage">
<div class="row">
<button class="ib" aria-label="Like" aria-pressed="false" data-tip="Like"><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></button>
<button class="ib" aria-label="Bookmark" aria-pressed="false" data-tip="Bookmark"><svg viewBox="0 0 24 24"><path d="M6 3h12v18l-6-4-6 4z"/></svg></button>
<button class="ib" id="share" aria-label="Share" data-tip="Share"><svg viewBox="0 0 24 24"><path d="M12 3l5 5-1.4 1.4L13 6.8V16h-2V6.8L8.4 9.4 7 8zM5 14h2v5h10v-5h2v7H5z"/></svg></button>
</div>
</div>
<script>
document.querySelectorAll('.ib[aria-pressed]').forEach(b=>b.addEventListener('click',()=>{
const on=b.getAttribute('aria-pressed')!=='true';b.setAttribute('aria-pressed',on);
b.classList.remove('pop');void b.offsetWidth;if(on)b.classList.add('pop');
}));
const share=document.getElementById('share');
share.addEventListener('click',()=>{share.dataset.tip='Copied';setTimeout(()=>share.dataset.tip='Share',1200);});
</script>
</body></html>