Back

Creating an Elegant Button with Shimmering Animation Effect

A detailed guide on implementing a polished button with a dynamic shine effect using pure CSS animations.

HTML

The HTML structure is incredibly simple—just a single button element with the class "shine-btn".

        <button class="shine-btn">Button</button>
      

CSS

Let's start styling our button using the "shine-btn" class. We'll create a clean, modern appearance by removing the default border and adding a subtle 1px border radius for a slightly softer edge. The button will have a vibrant teal background (#00ffb3) and comfortable padding. The position is set to relative to establish a positioning context for our shine effect, and overflow is set to hidden to ensure the animation stays within the button boundaries.

        .shine-btn {
            border: none;
            border-radius: 1px;
            padding: 5px 20px;
            background: #00ffb3;
            position: relative;
            overflow: hidden;
        }
      
Now for the magic—we'll create the shimmering effect using the ::before pseudo-element. This element will act as our animated highlight that sweeps across the button. We set it to be 100px wide and the full height of the button with absolute positioning. The key to the shine effect is a linear gradient rotated 120 degrees, transitioning from transparent to a semi-transparent white and back to transparent, creating a diagonal highlight. Initially, we position it outside the left edge of the button (left: -100px) so it can slide in.

        .shine-btn:before {
            content: '';
            position: absolute;
            width: 100px;
            height: 100%;
            background-image: linear-gradient(
                120deg,
                rgba(255,255,255, 0) 30%,
                rgba(255,255,255, .8),
                rgba(255,255,255, 0) 70%
            );
            top: 0;
            left: -100px;
        }
      
Now we'll define the animation keyframes that control the movement of our shine effect. At the beginning (0%), the shine is positioned outside the button at -100px. By 20% of the animation duration, it moves completely across the button to the right edge (100%). We maintain this position for the remaining 80% of the animation cycle, creating a pause before the next shine effect begins. This creates a more natural, periodic shimmer rather than a continuous movement.

        @keyframes shine {
            0% {left: -100px}
            20% {left: 100%}
            100% {left: 100%}
        }
      
Finally, we apply the animation to our ::before pseudo-element using the animation property. We set it to run for 3 seconds, repeat infinitely, and use linear timing to maintain a consistent speed throughout the animation.

        .shine-btn:before {
            content: '';
            position: absolute;
            width: 100px;
            height: 100%;
            background-image: linear-gradient(
                120deg,
                rgba(255,255,255, 0) 30%,
                rgba(255,255,255, .8),
                rgba(255,255,255, 0) 70%
            );
            top: 0;
            left: -100px;
            animation: shine 3s infinite linear; /* Animation */
        }
      
And there you have it—a beautiful button with an elegant shimmering effect that adds visual interest and a premium feel to your interface elements.

Variations: hover shine, smoother animation and reduced motion

The version above sweeps the shine forever. Three changes cover most real projects: run the shine only on hover, move it with transform instead of left, and turn it off for people who ask for less motion.

1. Move the shine with transform

Animating left changes the element's geometry, so the browser recalculates layout on every frame. transform does not affect layout, and browsers can often run it on the compositor, which keeps the sweep smooth when many buttons are on screen. Percentages in translateX() are relative to the pseudo-element itself, not the button. So instead of a fixed 100px strip, the ::before covers the whole button (inset: 0) and the gradient draws the bright band in the middle. translateX(-100%) parks it just outside the left edge and translateX(100%) just outside the right edge, whatever the button width.

        .shine-btn:before {
            content: '';
            position: absolute;
            inset: 0;
            background-image: linear-gradient(
                120deg,
                rgba(255,255,255, 0) 30%,
                rgba(255,255,255, .8),
                rgba(255,255,255, 0) 70%
            );
            transform: translateX(-100%);
            animation: shine 3s infinite linear;
        }

        @keyframes shine {
            0% {transform: translateX(-100%)}
            20%, 100% {transform: translateX(100%)}
        }
      

2. Shine on hover only

For a calmer UI, drop the infinite animation and sweep once when the pointer enters. Adding :focus-visible gives keyboard users the same effect. When the pointer leaves, the shine slides back to its start position.

        .shine-btn--hover:before {
            animation: none;
            transition: transform .6s ease;
        }
        .shine-btn--hover:hover:before,
        .shine-btn--hover:focus-visible:before {
            transform: translateX(100%);
        }
      
Use it as <button class="shine-btn shine-btn--hover">Button</button> together with the transform version above.

3. Respect reduced motion

A looping highlight is decorative. Users who enable "reduce motion" in their operating system should get a still button. With the animation and transition removed, the strip stays parked outside the button, and overflow: hidden keeps it invisible.

        @media (prefers-reduced-motion: reduce) {
            .shine-btn:before {
                animation: none;
                transition: none;
            }
        }
      

Tuning the effect

- Speed and pause: the shine travels during the first 20% of the 3s cycle (about 0.6s) and rests for the remaining 2.4s. Change the duration or the 20% keyframe to adjust both. - Brightness: lower the .8 alpha in the gradient for a subtler shimmer. A bright white band can wash out light text on pale buttons. - Angle: 120deg gives a diagonal streak. 90deg makes the band vertical. - Shine under the text: the positioned ::before paints above the label. To keep the label on top, wrap it in a <span> with position: relative and z-index: 1. - Rounded corners: overflow: hidden also clips the strip to the button's border-radius, so a pill-shaped button keeps its shape during the sweep.

Whole code

<button class="shine-btn">Button</button>

<style>
.shine-btn {
  border: none;
  border-radius: 1px;
  padding: 5px 20px;
  background: #00ffb3;
  position: relative;
  overflow: hidden;
}
.shine-btn:before {
  content: '';
  position: absolute;
  width: 100px;
  height: 100%;
  background-image: linear-gradient(
    120deg, 
    rgba(255,255,255, 0) 30%,
    rgba(255,255,255, .8),
    rgba(255,255,255, 0) 70%
  );
  top: 0;
  left: -100px;
  animation: shine 3s infinite linear;
}
@keyframes shine {
  0% {left: -100px}
  20% {left: 100%}
  100% {left: 100%}
}
</style>
      
Thank you for reading this article.

Comments

More buttons

Similar

See also