20 Pure CSS24 with JSPublished 2026-10-03Free · no sign-up
Every button you are likely to need, on one page: primary and secondary actions, a 3D press button, animated and glowing-border buttons, loading states, SVG stroke outlines and segmented button groups. Hand-written CSS buttons you can copy into any project: primary and secondary actions, a 3D press button, a loading state, a segmented group and a copy-to-clipboard button. Every one has visible keyboard focus, and the animated ones calm down for visitors who ask for reduced motion.
A primary call-to-action with a two-stop gradient and a soft coloured glow that grows on hover. The glow is a blurred pseudo-element behind the button, so the button itself never changes size and nothing around it shifts. Keyboard focus gets the same lift as hover.
An outline button for secondary actions. On hover a solid fill sweeps in from the left while the label switches to the dark ink colour, so the text keeps its contrast at every point of the animation. The sweep is a scaled background layer, which keeps it on the compositor and smooth on slow phones.
A chunky button with a solid bottom edge that sinks when you press it, like a physical key. The depth comes from a hard box-shadow, and the active state moves the button down by exactly the shadow height, so the base stays put. Good for games, quizzes and playful sign-up flows.
A submit button that swaps its label for a spinner while work is in progress, then shows a confirmation. The width is locked during loading so the layout does not jump, the button is disabled to stop double submits, and aria-busy tells screen readers what is happening.
A text button with an inline SVG arrow that slides forward on hover. The arrow is decorative, so it carries aria-hidden and the label alone names the action. Use it for 'Read more', 'Continue' and 'Next step' links where you want a hint of motion without a loud animation.
Three buttons joined into one pill for switching views, such as Day, Week and Month. It is built on radio inputs, so only one option can be on, arrow keys move between options for free, and it works with JavaScript turned off. The selected option uses the accent fill.
A dark button whose border has a moving highlight that travels around the edge. The beam is a rotating conic gradient clipped to the border with a padding-box and border-box background pair, so there are no extra elements. The animation stops for visitors who ask for reduced motion.
A small button that copies text to the clipboard and confirms it with a tick and a 'Copied' label for a moment. It uses the Clipboard API, announces the result through a polite live region for screen readers, and tells the visitor to press Ctrl+C when the browser blocks clipboard access.
document.querySelectorAll('.ttb-copy button').forEach(function (btn) {
var sr = btn.parentNode.querySelector('.ttb-copy-sr');
btn.addEventListener('click', function () {
var text = btn.getAttribute('data-copy');
var done = function (ok) {
btn.textContent = ok ? '✓ Copied' : 'Press Ctrl+C';
btn.classList.toggle('is-copied', ok);
sr.textContent = ok ? 'Copied to clipboard' : 'Copy failed';
setTimeout(function () { btn.textContent = 'Copy'; btn.classList.remove('is-copied'); }, 1600);
};
if (navigator.clipboard) navigator.clipboard.writeText(text).then(function () { done(true); }, function () { done(false); });
else done(false);
});
});
09. Like Button with Burst
AnimatedToggle
Pressing like fills the heart, pops it slightly larger and sends out a ring of small dots, all from CSS on the pressed state. The button is a toggle with aria-pressed and its count updates in the same text, so the state is clear without the burst.
var b = document.querySelector('.abt1'), c = b.querySelector('.c');
b.onclick = function () { var on = b.getAttribute('aria-pressed') !== 'true'; b.setAttribute('aria-pressed', on); c.textContent = +c.textContent + (on ? 1 : -1); };
10. Send Button with Paper Plane
AnimatedFeedback
On click the paper plane flies off to the top right, the label changes to Sent, and a moment later everything returns. The flight is a keyframe on the icon only, the label change is real text, and a live region announces Message sent.
var b = document.querySelector('.abt2 button'), l = b.querySelector('.l'), live = document.querySelector('.abt2 .sr');
b.onclick = function () { if (b.classList.contains('go')) return; b.classList.add('go'); l.textContent = 'Sent'; live.textContent = 'Message sent'; setTimeout(function () { b.classList.remove('go'); l.textContent = 'Send'; }, 1800); };
11. Follow to Following Swap
AnimatedToggle
The Follow label slides up and away as Following with a tick slides in, and turns quiet grey so the pressed state does not shout. Both labels sit in the same grid cell, so the button is always as wide as the longer one and nothing jumps when they swap.
var b = document.querySelector('.abt3');
b.onclick = function () { var on = b.getAttribute('aria-pressed') !== 'true'; b.setAttribute('aria-pressed', on); };
12. Add to Cart Fly-In
AnimatedEcommerce
A dot flies from the Add to cart button into the cart icon along a curve, then the cart count bumps. The curve comes from animating the x and y offsets on two nested elements with different easings, a classic trick for arcs without paths.
var w = document.querySelector('.abt4'), n = w.querySelector('.n'), cart = w.querySelector('.cart'), k = 0;
w.querySelector('button').onclick = function () {
var fx = document.createElement('span'); fx.className = 'fx'; fx.innerHTML = '<i></i>'; fx.setAttribute('aria-hidden', 'true'); w.appendChild(fx);
setTimeout(function () { fx.remove(); k++; n.textContent = k; cart.setAttribute('aria-label', 'Cart, ' + k + (k === 1 ? ' item' : ' items')); n.classList.remove('bump'); void n.offsetWidth; n.classList.add('bump'); }, matchMedia('(prefers-reduced-motion: reduce)').matches ? 0 : 600);
};
13. Confetti Celebration Button
AnimatedCelebration
Completing a task sprays a short burst of confetti from the button. The pieces are a dozen small spans given random directions through custom properties, removed after one second, and skipped entirely under reduced motion.
View code
<div class="abt5"><button>Mark as done</button></div>
var w = document.querySelector('.abt5'), b = w.querySelector('button'), cols = ['#f43f5e', '#f59e0b', '#22c55e', '#3b82f6', '#a855f7'];
b.onclick = function () {
var done = b.classList.toggle('done'); b.textContent = done ? 'Done ✓' : 'Mark as done';
if (!done || matchMedia('(prefers-reduced-motion: reduce)').matches) return;
for (var i = 0; i < 14; i++) { var s = document.createElement('span'), a = Math.random() * Math.PI * 2, d = 60 + Math.random() * 60; s.className = 'cf'; s.setAttribute('aria-hidden', 'true');
s.style.cssText = '--c:' + cols[i % 5] + ';--x:' + Math.cos(a) * d + 'px;--y:' + Math.sin(a) * d + 'px;--r:' + (Math.random() * 720 - 360) + 'deg';
w.appendChild(s); setTimeout(s.remove.bind(s), 1000); }
};
14. Press and Hold to Confirm
AnimatedDestructive
A destructive button that only fires after being held for a second and a half, with a fill showing progress. It works with the pointer and with Space or Enter held on the keyboard, and releasing early cancels. The instruction is in the button's description.
View code
<div class="abt6"><button aria-describedby="abt6h"><span class="f" aria-hidden="true"></span><span class="l">Hold to delete</span></button><p id="abt6h">Press and hold for 1.5 seconds.</p></div>
var b = document.querySelector('.abt6 button'), l = b.querySelector('.l'), t;
function start(e) { if (e.type === 'keydown' && (e.repeat || (e.key !== ' ' && e.key !== 'Enter'))) return; if (e.type === 'keydown') e.preventDefault(); if (b.classList.contains('ok')) return; b.classList.add('hold'); t = setTimeout(function () { b.classList.remove('hold'); b.classList.add('ok'); l.textContent = 'Deleted'; }, 1500); }
function stop() { clearTimeout(t); b.classList.remove('hold'); }
b.addEventListener('pointerdown', start); b.addEventListener('keydown', start);
['pointerup', 'pointerleave', 'keyup', 'blur'].forEach(function (ev) { b.addEventListener(ev, stop); });
b.addEventListener('click', function (e) { e.preventDefault(); });
15. Subscribe with Ringing Bell
AnimatedToggle
Subscribing turns the button solid and gives its bell a short ring, a satisfying confirmation borrowed from video platforms. The ring plays once when the pressed state becomes true and never loops.
var b = document.querySelector('.abt7'), s = b.querySelector('span');
b.onclick = function () { var on = b.getAttribute('aria-pressed') !== 'true'; b.setAttribute('aria-pressed', on); s.textContent = on ? 'Subscribed' : 'Subscribe'; };
16. Rotating Conic Glow Border
GlowAnimation
A conic gradient spins behind the button and only a 2px ring of it shows, with a blurred copy underneath for the glow. The angle is a registered @property so the browser can animate it; browsers without @property show the ring standing still.
At rest this is a plain outlined button. On hover and focus the border turns cyan and stacked box-shadows, one tight, one wide and one inset, create a neon glow. Animating box-shadow is acceptable here because the transition is short and only runs on interaction.
A ring of glow expands from the button and fades every two seconds, to draw the eye to a single action such as Go live. The ring is an animated box-shadow on a pseudo-element. Use it sparingly, and never on more than one button in view.
A narrow beam of light travels around the border: a conic gradient with one bright slice, masked so only a 1.5px ring is visible. The mask is two layers combined with exclude, which cuts the inside out and leaves the button background untouched.
On a light page a neon glow looks out of place, so this one uses a coloured, blurred shadow under the button instead. The shadow is the button colour at low opacity and grows slightly on hover, which reads as glow and lift together.
A radial highlight on the border follows the pointer. A few lines of script write the pointer position into two custom properties, and the border is a masked radial gradient centred on them. Without JavaScript the button simply has a plain border.
var b = document.querySelector('.gbb6');
b.addEventListener('pointermove', function (e) {
var r = b.getBoundingClientRect();
b.style.setProperty('--x', (e.clientX - r.left) + 'px');
b.style.setProperty('--y', (e.clientY - r.top) + 'px');
});
22. Glowing Selected Option
GlowGroup
Glow as a selection state: three billing buttons in a group, and the one with aria-pressed set to true glows. Clicking moves the glow, and the pressed state is announced, so the highlight is never the only cue.
document.querySelectorAll('.gbb7 button').forEach(function (b, _, all) {
b.addEventListener('click', function () { all.forEach(function (x) { x.setAttribute('aria-pressed', x === b ? 'true' : 'false'); }); });
});
23. Button with Inline Spinner
LoadingSpinner
Clicking shows a spinner, changes the label to Saving and sets aria-busy and aria-disabled. A minimum width stops the button from jumping as the label changes. After a pretend two-second request it returns to normal.
var b = document.querySelector('.lb1'), t = b.querySelector('.t');
b.addEventListener('click', function () {
if (b.getAttribute('aria-busy') === 'true') return;
b.setAttribute('aria-busy', 'true'); b.setAttribute('aria-disabled', 'true'); t.textContent = 'Saving…';
setTimeout(function () { b.removeAttribute('aria-busy'); b.removeAttribute('aria-disabled'); t.textContent = 'Save changes'; }, 2000);
});
24. Button That Fills as Progress
LoadingProgress
The button background fills from left to right like a progress bar while an upload runs, then turns green with Done. The percentage is in the label so it can be read, and the label is a polite live region so the finish is announced.
var b = document.querySelector('.lb2'), t = b.querySelector('.t');
b.addEventListener('click', function () {
if (b.dataset.run) return;
b.dataset.run = 1; b.classList.remove('done');
var p = 0, id = setInterval(function () {
p += 10; b.style.setProperty('--p', p + '%'); t.textContent = 'Uploading ' + p + '%';
if (p >= 100) { clearInterval(id); b.classList.add('done'); t.textContent = 'Done ✓'; delete b.dataset.run; }
}, 180);
});
25. Three Dots Loading State
LoadingDots
The label is swapped for three bouncing dots while waiting, and a visually hidden Sending message keeps the button's name meaningful for screen readers. The fixed width means the layout does not jump when the label disappears.
var b = document.querySelector('.lb3');
b.addEventListener('click', function () {
if (b.classList.contains('busy')) return;
b.classList.add('busy'); b.setAttribute('aria-disabled', 'true');
setTimeout(function () { b.classList.remove('busy'); b.removeAttribute('aria-disabled'); }, 2200);
});
26. Loading to Success Morph
LoadingSuccess
A wide button shrinks into a circle with a spinner, then shows a tick and expands again. Width and border-radius transition together, which works because the button has an explicit width in each state. The result is announced through a live region below.
While busy, a light shimmer sweeps across the button, a calm alternative to a spinner for short waits. Your fetch code only has to toggle one class and the disabled property, and the label changes to say what is happening. Focus returns to the button when it is done.
var b = document.querySelector('.lb5');
b.addEventListener('click', function () {
b.classList.add('is-loading'); b.disabled = true; b.textContent = 'Refreshing…';
setTimeout(function () { b.classList.remove('is-loading'); b.disabled = false; b.textContent = 'Refresh data'; b.focus(); }, 2000);
});
28. Progress Ring Icon Button
LoadingIcon
A round download button whose border becomes a progress ring drawn with a conic gradient, so no SVG ring is needed. The fill comes from a custom property, and the aria-label is updated with the progress so the state is available to screen readers as well as shown.
var b = document.querySelector('.lb6');
b.addEventListener('click', function () {
if (b.dataset.run) return;
b.dataset.run = 1;
var p = 0, id = setInterval(function () {
p += 5; b.style.setProperty('--p', p);
b.setAttribute('aria-label', 'Downloading, ' + p + ' percent');
if (p >= 100) { clearInterval(id); b.setAttribute('aria-label', 'Download complete'); delete b.dataset.run; }
}, 90);
});
29. Busy Button That Blocks Double Submits
LoadingForms
A real form whose submit button turns busy on submit and ignores further clicks, which prevents double orders. It uses aria-disabled rather than disabled, so the button stays focusable and keyboard users do not lose their place.
var f = document.querySelector('.lb7'), b = f.querySelector('button'), out = f.querySelector('p');
f.addEventListener('submit', function (e) {
e.preventDefault();
if (b.getAttribute('aria-disabled') === 'true') return;
b.setAttribute('aria-disabled', 'true'); b.textContent = 'Sending…'; out.textContent = '';
setTimeout(function () { b.removeAttribute('aria-disabled'); b.textContent = 'Request invite'; out.textContent = 'Invite requested. Check your inbox.'; }, 1800);
});
30. Border That Draws Itself
SVGHover
An SVG rectangle sits over the button and its stroke is hidden with stroke-dasharray and stroke-dashoffset. On hover or keyboard focus the offset animates to zero, so the outline draws around the button in one continuous line. pathLength="100" keeps the dash maths simple at any size.
A short bright dash travels round the border on a loop, made by a dash pattern of 18 visible units and 82 gaps whose offset is animated. It suits one important call to action. The animation stops for visitors who prefer reduced motion, leaving a static highlight.
At rest only the four corners of the frame show, like camera brackets. The stroke-dasharray is a list of nine values worked out from the real side lengths so each dash sits on a corner. On hover every dash grows and every gap shrinks to zero, closing the frame evenly from all four corners.
A solid button whose arrow icon is redrawn line by line when the pointer arrives: the shaft first, then the head after a short delay. The label is the accessible name and the icon is aria-hidden, so screen readers hear only Continue.
Clicking toggles aria-pressed, and the pressed state swaps the label to Saved while a tick is drawn inside a filled circle. The state lives on the button itself, so assistive technology announces it as a toggle button that is pressed or not pressed.
The outline is an SVG stroke painted with a linearGradient, which a CSS border cannot do on a rounded shape without extra layers. A drop-shadow filter adds a soft glow that brightens on hover, and the label stays plain white for contrast.
A text link whose underline is a hand-drawn wave in an inline SVG, drawn from left to right on hover and focus with stroke-dashoffset. Because it is a real link it keeps link semantics, and the wave stretches with the text because preserveAspectRatio is none.
View code
<a class="ssb7" href="#pricing">See pricing<svg viewBox="0 0 120 10" preserveAspectRatio="none" aria-hidden="true"><path d="M1 5 Q 8 0 15 5 T 29 5 T 43 5 T 57 5 T 71 5 T 85 5 T 99 5 T 113 5 T 119 5" pathLength="1"/></svg></a>
Three buttons joined into one control, with shared borders and rounded outer corners only. The group is a role="group" with a label, so screen readers announce its purpose, and adjacent borders collapse with a negative margin.
An editor toolbar made of icon buttons in a pill, using role="toolbar" with arrow-key navigation so the group is one Tab stop. Each icon button has an aria-label, and toggle buttons such as Bold report their state with aria-pressed.
A rounded segmented control for switching a view between Day, Week and Month. It is built from buttons with aria-pressed rather than radios, which suits toolbars where the change happens straight away, and the active segment is raised.
The common footer pair of a quiet Cancel and a bold Save, aligned to the right. The primary action comes last in reading order to match most platforms, and both buttons have equal height so the pair looks balanced.
Page number buttons in an attached group with Previous and Next at the ends. It is a nav landmark labelled Pagination, the current page is marked with aria-current, and Previous is disabled on the first page.
A vertical group of actions for sidebars and side panels, with full-width buttons that share borders. A destructive action at the bottom is separated by a gap and coloured red, so it is not pressed by accident.
A wrapping group of toggle chips for quick filters, where several can be on at once. Each chip is a button with aria-pressed, a tick appears on active chips, and a Clear button resets them all in one click.
A minus, number and plus group for cart quantities. The buttons are named Decrease and Increase quantity, the number is a real input with min and max, and the minus button disables itself at the minimum.
A button has one job: to look pressable and say what happens next. Give it a label that names the action ("Save changes", not "Submit"), at least 44 by 44 pixels of tap area on touch screens, and a focus style you can actually see. Hover effects are a bonus for mouse users; they should never be the only way to tell that something is clickable.
Button or link?
Use a <button> when the click does something on the page, such as submitting a form, opening a menu or copying text. Use an <a href> when it takes the visitor to another page. Styling an anchor to look like a button is fine; using a div with a click handler is not, because keyboards and screen readers cannot reach it.
Animating buttons without jank
Animate transform and opacity, not width, height or margins. The demos here move glows, fills and arrows with transforms or on pseudo-elements, so the button never changes size and the content around it never shifts. Keep hover transitions short, between 150 and 300 milliseconds, so the button feels responsive.
How to use these demos
Each demo is scoped with its own class prefix (.ttb-), so you can paste several into one page without collisions. Click Open in editor to change colours and text with a live preview, then copy the result. The colours use the same blue palette as this site; swap the hex values for your brand.
Frequently asked questions
Are these CSS buttons free to use?
Yes. You can copy them into personal and commercial projects. No sign-up and no attribution required.
Do they need a framework?
No. They are plain HTML and CSS. Two demos add a few lines of vanilla JavaScript for the loading and copy states.
Will they work on mobile?
Yes. They use relative layout, readable font sizes and tap areas large enough for a finger. Hover effects simply do not trigger on touch screens; the buttons still work.