Skip to content

CSS Animations Showcase

Medium ~35 min

What you'll build

A showcase page with a bouncing ball (keyframes), a hover card (transitions), a rotating spinner (transform), and a fade-in-on-scroll section (IntersectionObserver).

Goals

  • Use @keyframes for looping animations
  • Apply transitions for smooth state changes
  • Use transform for GPU-accelerated movement
  • Trigger animations on scroll with IntersectionObserver

Prerequisites

  • CSS transitions and transforms
  • JavaScript IntersectionObserver
  • HTML structure

Steps

  1. 1

    Build the bouncing ball with keyframes

    Create a ball div and a @keyframes animation that moves it up and down infinitely using transform: translateY (GPU-friendly).

    Code
    <div class="ball"></div>
    <style>
    .ball {
      width: 50px; height: 50px;
      border-radius: 50%;
      background: #3b82f6;
      animation: bounce 1s ease-in-out infinite alternate;
    }
    @keyframes bounce {
      from { transform: translateY(0); }
      to   { transform: translateY(-100px); }
    }
    </style>

    Expected result

    A blue ball bounces up and down continuously.

  2. 2

    Add a hover card with transitions

    Create a card that lifts and casts a shadow on hover using transition properties. Transitions animate between the default and hover states.

    Code
    <div class="card">Hover me</div>
    <style>
    .card {
      padding: 2rem; background: white; border-radius: 8px;
      transition: transform 0.3s, box-shadow 0.3s;
    }
    .card:hover {
      transform: translateY(-8px);
      box-shadow: 0 12px 24px rgba(0,0,0,0.15);
    }
    </style>

    Expected result

    Hovering the card lifts it smoothly and adds a shadow.

  3. 3

    Build a rotating spinner

    Create a loading spinner using a border trick and a rotate keyframe. This is the classic CSS-only spinner seen in most web apps.

  4. 4

    Add scroll-triggered fade-in

    Create a section that starts opacity:0 and fades in when it enters the viewport. Use IntersectionObserver to add a .visible class.

    Code
    <section class="reveal">Scroll to see me fade in</section>
    <style>
    .reveal { opacity: 0; transition: opacity 0.6s; }
    .reveal.visible { opacity: 1; }
    </style>
    <script>
    const obs = new IntersectionObserver((entries) => {
      entries.forEach(e => {
        if (e.isIntersecting) e.target.classList.add('visible');
      });
    });
    document.querySelectorAll('.reveal').forEach(el => obs.observe(el));
    </script>

    Expected result

    Scrolling down reveals the section with a smooth fade-in.

  5. 5

    Combine into a showcase page

    Put all four demos on one page with headings. Test that each animation performs smoothly (no layout thrashing — only transform and opacity are animated).

Try it yourself

What you learned

You mastered the four most-used CSS animation techniques and learned why transform/opacity are preferred — they avoid layout thrashing and run on the GPU.

Related Resources

Related Lessons

Look up unfamiliar terms

A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.

View glossary

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to topic