CSS Effect Tips

Twelve small effects that make a page feel polished, each with a live demo and the CSS to copy. No JavaScript, no libraries.

Tip 1

Frosted glass panel

backdrop-filter blurs whatever sits behind the element. Pair it with a translucent background and a thin light border. It needs something colorful behind it to look like glass.

.glass {
  background: rgb(255 255 255 / .15);
  backdrop-filter: blur(12px) saturate(140%);
  border: 1px solid rgb(255 255 255 / .3);
  border-radius: 14px;
}
Frosted glass
Tip 2

Gradient text

Paint a gradient as the background, clip it to the letters, and make the text color transparent. Animate background-position to make it drift.

.grad-text {
  background: linear-gradient(90deg, #5b5bd6, #e5487a, #1fb5a8, #5b5bd6);
  background-size: 300% 100%;
  background-clip: text;
  color: transparent;
  animation: slide 6s linear infinite;
}
@keyframes slide { to { background-position: 300% 0; } }
Gradient
Tip 3

Hover lift

Move the card up a few pixels and deepen its shadow. Animate only transform and box-shadow, and use an ease-out curve so it feels quick.

.card {
  transition: transform .25s cubic-bezier(.2, .8, .2, 1),
              box-shadow .25s;
}
.card:hover {
  transform: translateY(-6px);
  box-shadow: 0 14px 30px rgb(0 0 0 / .14);
}
Hover meA card that lifts toward you.
Tip 4

Spinning gradient border

Two backgrounds: a solid one clipped to the padding box and a conic gradient on the border box. Register the angle with @property so the browser can animate it.

@property --angle {
  syntax: "<angle>"; initial-value: 0deg; inherits: false;
}
.ring {
  border: 3px solid transparent;
  background:
    linear-gradient(#fff, #fff) padding-box,
    conic-gradient(from var(--angle), #5b5bd6, #e5487a, #1fb5a8, #5b5bd6) border-box;
  animation: spin 4s linear infinite;
}
@keyframes spin { to { --angle: 360deg; } }
Gradient border
Tip 5

Underline that grows

Draw the underline as a background image and grow its width on hover. It wraps across lines, unlike a pseudo-element.

a {
  text-decoration: none;
  background: linear-gradient(currentColor, currentColor)
              left bottom / 0% 2px no-repeat;
  transition: background-size .3s ease;
}
a:hover, a:focus-visible { background-size: 100% 2px; }
Tip 6

Shine sweep

A diagonal highlight in a pseudo-element, parked off to the left, slides across on hover. Put the transition only on the hover state so it doesn't sweep back.

.btn { position: relative; overflow: hidden; }
.btn::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(120deg, transparent 30%,
              rgb(255 255 255 / .45) 50%, transparent 70%);
  transform: translateX(-100%);
}
.btn:hover::after {
  transform: translateX(100%);
  transition: transform .7s ease;
}
Tip 7

Clip-path reveal

Animating clip-path between two shapes of the same kind reveals one layer over another. Circles, insets and polygons with the same point count all animate.

.over {
  clip-path: circle(0% at 50% 50%);
  transition: clip-path .5s ease;
}
.box:hover .over {
  clip-path: circle(75% at 50% 50%);
}
Hover me
Revealed
Tip 8

Neon glow

Stack several text-shadows with growing blur: a tight white one for the tube, wider colored ones for the glow. Works best on a dark background.

.neon {
  color: #fff;
  text-shadow: 0 0 4px #fff,
               0 0 12px #e5487a,
               0 0 28px #e5487a,
               0 0 48px #e5487a;
}
GLOW
Tip 9

Style a parent with :has()

:has() lets an element react to what's inside it. Here the whole card changes when its checkbox is ticked, with no JavaScript.

.card:has(input:checked) {
  border-color: #1fb5a8;
  background: color-mix(in srgb, #1fb5a8 12%, white);
}

The card highlights when it's selected.

Tip 10

Fade in on scroll

Scroll-driven animations tie a keyframe animation to an element's position in its scroll container. Wrap it in @supports so browsers without it just show the content.

@supports (animation-timeline: view()) {
  .row {
    animation: fade-up linear both;
    animation-timeline: view();
    animation-range: entry 0% cover 35%;
  }
}
@keyframes fade-up {
  from { opacity: 0; transform: translateY(24px) scale(.96); }
}
Scroll inside this box
Item two
Item three
Item four
Item five
Item six
Item seven
Item eight
Needs a recent Chrome, Edge or Safari.
Tip 11

Skeleton shimmer

A placeholder while content loads: a wide gradient that slides across gray blocks. It tells people something is coming without a spinner.

.skel {
  background: linear-gradient(90deg,
    #eee 25%, #ddd 50%, #eee 75%) 0 0 / 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
Tip 12

Focus rings for keyboards only

:focus-visible shows a ring when someone tabs to a control, but not when they click it. Never remove focus styles without a replacement.

button:focus { outline: none; }
button:focus-visible {
  outline: 3px solid #5b5bd6;
  outline-offset: 3px;
}
Click, then press Tab.
Bonus

Respect reduced motion

Some people get dizzy from movement and turn it off in their system settings. One media query switches off animations for them. This page uses it.

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

Turn on "Reduce motion" in your system settings and the effects above stop moving.