.
Skip to live previewA free premium cancel button UI component with infinite red glow pulse animation, sweeping shine hover effect, lift and scale transform, ghost-to-solid fill on hover, and 30 floating ambient background particles generated with JavaScript. Pure HTML, CSS, and vanilla JavaScript. Zero libraries. Copy-paste ready.
Exactly how every CSS animation, transition, and JavaScript particle in the Stunning Cancel Button works.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Stunning Cancel Button</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<!-- Floating particles container (filled by JS) -->
<div class="particles" id="particles"></div>
<!-- Cancel button: .pulse class enables glow animation -->
<button class="cancel-btn pulse" onclick="handleCancel()">
<span>Cancel Action</span>
</button>
<script src="script.js"></script>
</body>
</html>
How the CSS pulse animation, shine sweep, lift effect, and floating particles work.
The glow pulse uses @keyframes on the box-shadow property. At 0%, the shadow has 0px spread and 0.7 opacity. At 70%, the spread has grown to 20px but opacity is already 0 — so the ripple appears to expand outward and fade. At 100% it resets to 0px spread, invisible, ready for the next loop. animation: pulse 2s infinite repeats this indefinitely. The key insight is that spread-radius (the third box-shadow value) can be animated to create an expanding ring effect.
The shine uses the ::before pseudo-element with position: absolute, left: -100%, and a three-stop white linear gradient (transparent → rgba(255,255,255,0.3) → transparent). The button has overflow: hidden which clips anything outside its bounds. On :hover, transition: all 0.7s smoothly moves left to 100%. As the gradient crosses the button's visible area from left to right, it appears as a sweeping gloss highlight. Once left reaches 100%, the element is off-screen again until the next hover.
The lift uses transform: translateY(-8px) scale(1.05) on :hover with transition: all 0.4s ease. Negative translateY moves the element upward (negative = up in CSS). scale(1.05) enlarges it 5%. The :active rule reduces both to translateY(-4px) scale(1.02) — simulating the button being pressed back down. The box-shadow increases on hover from 0 10px 30px rgba(0,0,0,0.3) to 0 20px 40px rgba(231,76,60,0.6), reinforcing the appearance of depth and elevation.
In the DOMContentLoaded event, loop 30 times. Each iteration creates a div with classList.add('particle'). Set a random width with Math.random() * 8 + 'px' and copy to height for a perfect circle. Set left to Math.random() * 100 + '%' for horizontal spread. Set animationDelay to Math.random() * 15 + 's' to stagger start times (prevents all particles starting at the same position). Set animationDuration to 10 + Math.random() * 10 + 's' for varied speeds. The CSS @keyframes float moves each from translateY(100vh) to translateY(-100vh) with opacity fading in at 10% and out at 90%.
A ghost button has background: transparent with a visible border (here: 3px solid rgba(255,255,255,0.6)) and colored text. This creates an outline/hollow button that shows the background design behind it. On hover or click, the background fills with a solid color — in this case #e74c3c red — and the border matches. This pattern works well for secondary actions or on gradient/image backgrounds where a solid button would hide the background. The transition: all 0.4s ease makes the fill appear smoothly rather than snapping instantly.
pointer-events: none on the .particles container tells the browser to ignore all mouse and touch events on that element and its children. Without this, the 30 particle divs positioned absolutely over the page would intercept click events, potentially blocking the cancel button from being clicked. Since the particles are purely decorative background elements, they should never receive interaction. This property is also useful for overlays, tooltips, and any purely visual decoration that sits above interactive elements.
Free courses in JavaScript, HTML, CSS, Python, SQL, DSA, Kotlin, C, C++, C#. Zero account needed.