Button Snippets — Free HTML CSS JS Copy-Paste Buttons

34 button components · Primary, Ghost, Loading, Ripple, Magnetic, Neon, Confetti · Exports to React, Vue, Angular & Tailwind

Share & Support

What's included

Features

9 button components covering every production use case
Primary, secondary, ghost, danger variants sharing a base .btn class
Loading button: CSS spinner + idle/loading/success 3-state class machine
Ripple button: getBoundingClientRect click-origin, CSS scale keyframe, element cleanup
Magnetic button: requestAnimationFrame lerp loop with configurable attraction radius
Neon glow: 3-layer box-shadow (inner/mid/outer) in 4 cyberpunk hue variants
Confetti: 80 physics particles, polar coordinates, gravity, CSS custom property trajectories
Social login: Google/GitHub/X brand buttons + OR divider + email fallback
Badge chips: status badges (green/yellow/red) + removable filter chips with × button

About this tool

Button Snippets — Free, Every Button Variant From Basic CTAs to Magnetic Micro-Interactions

Buttons are the most-clicked element in any web interface. Whether you need a basic four-variant CTA group for a form footer, a loading state for an async submission, or dramatic micro-interactions like magnetic cursor attraction and physics-based confetti, this collection covers every button pattern used in production web products.

Every snippet is plain HTML, CSS, and vanilla JavaScript. No React, no npm install, no build step. Copy the code and drop it into any project immediately.

Button Group provides four semantic variants — primary (filled accent), secondary (muted fill), ghost (transparent with border), and danger (red) — all sharing a base .btn class that controls padding, border-radius, font weight, and transition. Each variant overrides only colour. This is the starting point for any form footer, modal action row, or inline action group.

Loading Button implements a three-state machine: idle → loading → success. On click, a CSS spinner appears and the label changes to "Saving…". When the async operation resolves, the button transitions to a green success state with a tick, then resets after 2 seconds. The state is managed purely by adding and removing CSS classes — no inline style changes.

Ripple Button creates a Material Design-style click ripple from the exact position of the mouse click. getBoundingClientRect() gives the button's position on screen. The click coordinates minus the button's top-left give the ripple origin as a percentage. A CSS keyframe scales the ripple from 0 to 4× size and fades it out. The element is created and removed on each click — no accumulated DOM nodes.

Magnetic Button uses vector math to attract the button toward the cursor when the mouse is within a configurable radius. requestAnimationFrame runs a lerp (linear interpolation) loop: the button's transform eases toward the target position at 12% per frame. When the cursor leaves the magnetic zone, the button eases back to its origin. This effect appears on premium agency sites and creative portfolios.

Neon Glow Buttons achieve the cyberpunk glow effect with layered box-shadow: an inner white shadow for the bright core, a mid-range shadow for the mid-glow, and an outer shadow for the ambient spread — all in the same hue. The effect uses zero images or SVGs.

Confetti Button fires 80 physics particles on click. Each particle has a random angle (polar coordinates), random speed, and a CSS custom property for its trajectory. gravity reduces the y velocity each frame. Particles fade out as they reach 100% opacity decay. The confetti runs entirely in JavaScript with DOM elements — no Canvas.

Copy to Clipboard uses the Clipboard API with async/await. Success: button label changes to "Copied!" and reverts after 1.5 seconds. Fallback for older browsers uses document.execCommand.

Social Login Buttons provide Google, GitHub, and X (Twitter) OAuth-style buttons with brand icons, an "OR" divider, and an email/password fallback. Each button has brand-correct colours and hover states.

Badge Chips covers both semantic status badges (Active, Pending, Error in green/yellow/red) and removable filter chips for tag management and search filter UIs.

Real-world uses

Common Use Cases

Form footers and modal action rows
Use the Button Group for any form submit/cancel pair or modal confirm/dismiss row. Primary for the confirm action, ghost for cancel, danger for irreversible destructive actions like delete or remove.
SaaS sign-up flows, checkouts, and OAuth
Social login buttons for OAuth entry points (Google, GitHub, X). Loading button for async form submissions — shows a spinner and "Saving…" state while awaiting the API response, then a success tick on completion.
Dark-themed, premium, and gaming interfaces
Neon glow buttons for cyberpunk game dashboards, dev tool landing pages, and dark-themed SaaS products. Magnetic button for premium agency portfolio sites where micro-interactions signal craftsmanship.
Study CSS and JavaScript interaction techniques
Each button teaches a specific technique: getBoundingClientRect for click coordinates, requestAnimationFrame lerp for smooth animation, CSS custom properties for particle trajectories, and the Clipboard API for async text copy.
Filter chips and tag management in search UIs
Badge chips for applied search filter displays, technology tag selectors, category filter rows, and any UI where users add and remove tags. The × button fires a remove handler and removes the chip from the DOM.
Purchase confirmations, achievement unlocks, rewards
Confetti button for e-commerce order completion screens, subscription confirmation pages, milestone achievement banners, and any moment where celebrating the user increases engagement and satisfaction.

Got questions?

Frequently Asked Questions

Yes — every button in this collection is plain HTML, CSS, and vanilla JavaScript. No React, Vue, Angular, or any package manager needed. Copy the HTML and CSS from the editor and paste directly into any .html file or template. The JavaScript uses no import statements — it runs as an inline script or a simple .js file in a script tag.

Copy the base .btn CSS class and keep it as-is. Each variant (primary, secondary, ghost, danger) only overrides the colour-related properties. Apply both classes: class="btn primary" for a filled primary button, class="btn ghost" for a transparent one. This way all variants share the same sizing, padding, font weight, border-radius, and transition — only the visual treatment differs.

In the setLoading() function, replace the setTimeout simulation with your actual fetch or axios call. The state flow is: call setLoading(true) on click → await your API → on success, call setState("success") to show the tick → on error, call setState("idle") and show an error message. The CSS class handling does not change — only the async code between the state transitions changes.

Button HTML elements are keyboard-focusable by default — Tab to focus, Enter or Space to activate. For full WCAG 2.1 compliance: ensure sufficient colour contrast (4.5:1 for normal text), add aria-label to any icon-only buttons, add aria-busy="true" during the loading state, and add aria-pressed="true" to toggle buttons. The ripple and magnetic effects are purely visual and do not affect keyboard or screen reader interaction.