.
Stunning Cancel Button by Coodeverse is a free premium cancel button UI component built with pure HTML, CSS, and vanilla JavaScript. It features an infinite CSS box-shadow glow pulse @keyframes animation, a sweeping shine hover effect via the ::before pseudo-element, lift and scale transform on hover, ghost-to-solid red fill on hover, and 30 floating ambient particles generated on DOMContentLoaded with random sizes, positions, delays, and durations. Zero external libraries. Full source code free at coodeverse.com/projects/stunning-cancel-button.
💡Glow:2s infinite pulse @keyframes
·
✨Shine:::before left:-100%→100%
·
⬆Hover:translateY(-8px) scale(1.05)
·
✦Particles:30 JS DOM divs
·
📦Libraries:Zero
Live Preview — Hover & Click!

✕ Technique Deep Dive

Exactly how every CSS animation, transition, and JavaScript particle in the Stunning Cancel Button works.

① CSS @keyframes
Glow Pulse Animation
Animates box-shadow spread-radius from 0px to 20px while simultaneously fading rgba opacity from 0.7 to 0. The 70% keyframe creates the clean outward ripple — by 70% the spread is maximum but already transparent, so the reset to 0 at 100% is invisible, starting a smooth next loop.
@keyframes pulse {
0% { box-shadow: 0 0 0 0 rgba(231,76,60,.7); }
70% { box-shadow: 0 0 0 20px rgba(231,76,60,0); }
100% { box-shadow: 0 0 0 0 rgba(231,76,60,0); } }
animation: pulse 2s infinite;
② CSS ::before
Shine Hover Sweep
The ::before pseudo-element sits off-screen at left: -100% with a three-stop white gradient (transparent → rgba 0.3 → transparent). On :hover, transition: all 0.7s moves it to left: 100%. Because the button has overflow: hidden, the gradient only shows while crossing the visible button area — creating a diagonal gloss sweep.
.cancel-btn::before {
left: -100%; width: 100%;
background: linear-gradient(90deg,
transparent, rgba(255,255,255,.3), transparent); }
.cancel-btn:hover::before { left: 100%; }
③ CSS transform
Lift & Scale + Active Press
:hover applies translateY(-8px) scale(1.05) — negative Y moves up, scale enlarges. :active halves both values to simulate pressing down: translateY(-4px) scale(1.02). transition: all 0.4s ease makes both hover-in and hover-out smooth. box-shadow jumps from 0 10px 30px to 0 20px 40px rgba(231,76,60,0.6) for added depth.
.cancel-btn:hover {
transform: translateY(-8px) scale(1.05); }
.cancel-btn:active {
transform: translateY(-4px) scale(1.02); }
④ CSS background
Ghost → Solid Fill
Default state is background: transparent with border: 3px solid rgba(255,255,255,0.6) — the ghost/outline button pattern. On hover, background fills to #e74c3c and border-color matches. transition: all 0.4s ease interpolates both the background fill and the border color simultaneously, creating a smooth reveal of the solid red state.
.cancel-btn { background: transparent;
border: 3px solid rgba(255,255,255,.6); }
.cancel-btn:hover {
background: #e74c3c;
border-color: #e74c3c; }
⑤ JavaScript DOM
Floating Particle Background
DOMContentLoaded loop runs 30 times. Each particle div gets: random width (Math.random()*8 + 'px'), height set equal for a perfect circle, random left (Math.random()*100 + '%'), random animationDelay (0–15s) so they stagger, and random animationDuration (10–20s) for varied speed. @keyframes float moves them from translateY(100vh) to translateY(-100vh) with opacity fade at 10% and 90%.
const w = Math.random() * 8 + 'px';
particle.style.width = w;
particle.style.height = w;
particle.style.left = Math.random()*100+'%';
particle.style.animationDelay = Math.random()*15+'s';
✕ Full Source Code
// index.html — Stunning Cancel Button
<!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>
// cancel_btn_faq

Glow Pulse, Shine & Particles — FAQ

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.

Master CSS Animations & JavaScript.
Build Premium UI Components.

Free courses in JavaScript, HTML, CSS, Python, SQL, DSA, Kotlin, C, C++, C#. Zero account needed.

Privacy About-us Contact Sitemap