Button Snippets — Free HTML CSS JS Copy-Paste Buttons
91 button components · Primary, Ghost, Loading, Ripple, Magnetic, Neon, Confetti · Exports to React, Vue, Angular & Tailwind
What's included
Features
About this category
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
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.
All 91 buttons snippets, A to Z
- 3D Push Button
- Add to Calendar Button
- Add to Cart Button
- AI Mode Glow Button (Google Search Style)
- AI Voice Input Button
- Animated Hamburger Menu
- App Badge API Demo
- Async Button with Real Progress Fill (Not a Fake Spinner)
- Async Submit Button — Idle/Loading/Success/Error State Machine
- Badge Dot Indicator
- Badges & Chips
- Bookmark Toggle
- Bootstrap Back to Top Button
- Bootstrap Copy-to-Clipboard Feedback
- Bootstrap Hold-to-Confirm Delete Button
- Bootstrap HTTP Status Badge
- Bootstrap Rate-Limited Action Button
- Bootstrap Social Login Buttons
- Button Group
- Canvas Confetti Burst Button
- Clipboard Paste Button
- Color Mode Toggle
- Color Theme Switcher
- Confetti Button
- Contact Picker Button
- Cooldown Ring Button
- Copy to Clipboard Button
- Distraction-Free Reading Mode Toggle
- Download Button
- Dual-Hold Safety Button
- Dyslexia-Friendly Reading Mode
- Elastic Spring Toggle Switch
- Emoji Reaction Bar
- Environment Badge
- Expanding FAB
- FAB Speed Dial Menu
- File System Access Save Dialog
- Floating Action Button Radial Menu
- Fly to Cart Button
- Fullscreen API Toggle Button
- Gradient Button
- High Contrast Mode Toggle
- Hold to Confirm Button
- Icon Toolbar — Roving Tabindex Keyboard Navigation
- Interactive Hover Button
- Jelly Press Button
- Keyboard Keys
- Like / Favorite Button
- Like Burst Button
- Liquid Button
- Load More Button
- Loading Button
- Long-Press Confirm with Radial Fill
- Lottie Button Micro Loader
- Lottie Hover Icon Button
- Magnetic Button
- Mash-to-Charge Button
- Neon Glow Buttons
- Neumorphic Button
- Notification Badge
- Particle Explosion Click Button
- Payment Request API Button
- Popmotion Spring Toggle Switch
- Print This Page Button
- Proximity Glow Button
- Pulse Button
- Push Notification Subscription Toggle
- Ripple Button
- Screen Orientation Lock Toggle
- Screen Wake Lock Toggle
- Segmented Toggle
- Shake to Undo
- Share Menu with Copy Link and Social Options
- Shimmer Button
- Snap.svg Morphing Icon Button
- Social Login Buttons
- Social Login Buttons
- Split Action Button with Dropdown
- Tactile Brutalist Press Button
- Text-to-Speech Button
- Theme Preference Persistence Demo
- Three-Way Theme Toggle Switch
- UI Click Sound Toggle
- Upvote / Downvote Widget
- Vibration API Pattern Demo
- Voting Buttons
- Web Share Button
- Web3 Wallet Connect Button
- WebAuthn Security Key Prompt
- WhatsApp Floating Button
- Wishlist Heart Button