Skip to main content

Command Palette

Search for a command to run...

CSS Transitions & Animations – Bringing Websites to Life

Updated
3 min readView as Markdown

Over the past few days, I've learned how to create responsive layouts using Flexbox, Grid, and Media Queries.

Today, I explored how to make websites more interactive and visually engaging with CSS Transitions and Animations.

A modern website doesn't just display information—it responds to user interactions. Buttons smoothly change color, cards gently lift on hover, and loading indicators move naturally.

CSS makes all of this possible without using JavaScript.

Let's dive in.


What is a CSS Transition?

A Transition creates a smooth change between two states of an element.

Without a transition, style changes happen instantly.

Example without transition:

button:hover{
    background:blue;
}

The color changes immediately.

With a transition:

button{
    transition:0.3s;
}

button:hover{
    background:blue;
}

The color changes smoothly over 0.3 seconds.


Transition Properties

Instead of transitioning everything, we can specify a property.

transition: background-color 0.4s;

General syntax:

transition: property duration timing-function delay;

Example:

transition: transform 0.5s ease;

Timing Functions

Timing functions control how the animation progresses.

Common values:

  • ease

  • linear

  • ease-in

  • ease-out

  • ease-in-out

Example:

transition: all 0.4s ease-in-out;

Transform Property

The transform property changes an element's appearance without affecting the document layout.

Scale

.card:hover{
    transform:scale(1.05);
}

Makes the element slightly larger.


Rotate

transform:rotate(15deg);

Rotates the element.


Translate

transform:translateX(30px);

Moves the element horizontally.


Skew

transform:skew(10deg);

Tilts the element.


What are CSS Animations?

Transitions require a trigger such as :hover.

Animations can run automatically and provide much more control.

Animations are created using @keyframes.


Creating Keyframes

@keyframes fadeIn{

    from{
        opacity:0;
    }

    to{
        opacity:1;
    }

}

This creates a simple fade-in effect.


Applying an Animation

.box{

    animation:fadeIn 2s;

}

The element gradually appears over two seconds.


Animation Properties

The shorthand syntax:

animation: name duration timing-function delay iteration-count direction;

Example:

animation: bounce 2s ease infinite;

Infinite Animations

animation-iteration-count: infinite;

The animation keeps repeating.

Useful for:

  • Loading indicators

  • Icons

  • Attention-grabbing effects


Alternate Direction

animation-direction: alternate;

Instead of jumping back to the start, the animation plays forward and then backward.


Transition vs Animation

Transition Animation
Needs a trigger Can run automatically
Simple state changes Complex motion sequences
Best for hover effects Best for loaders, banners, and effects

Both are important tools and are often used together.


Best Practices

✔ Keep animations smooth and subtle.

✔ Use transitions for hover effects.

✔ Avoid excessive movement that distracts users.

✔ Keep animation durations between 0.2s–0.6s for most interactions.

✔ Focus on improving user experience, not just adding visual effects.


My Biggest Takeaway

Before today, I thought animations always required JavaScript.

Now I understand that CSS alone can create smooth transitions and engaging animations.

Simple hover effects, scaling, fading, and movement can make a website feel much more polished and interactive.

Learning transitions and animations has shown me that good web design isn't just about layout—it's also about creating a pleasant experience for users.

2 views

100 Days of Code: My Journey to Becoming a Full Stack Developer

Part 29 of 50

Welcome to my 100 Days of Code journey! In this series, I'll document my daily progress as I learn Full Stack Web Development from the ground up. Every post will cover what I learned, challenges I faced, mistakes I made, and the projects I built. My goal is not just to complete 100 days but to become a better developer through consistency, discipline, and learning in public. Topics I'll cover include: • Git & GitHub • HTML, CSS & JavaScript • React.js • Node.js & Express • MongoDB • APIs • Real-world Projects • AI tools for Developers Whether you're just starting out or revising your fundamentals, I hope this journey helps you learn alongside me. Let's build, learn, and grow together! 🚀

Up next

Building My First Responsive Landing Page with HTML & CSS

Today marks my 30th day of the #100DaysOfCode challenge—a milestone I'm really proud of. Instead of learning a new CSS concept, I challenged myself to build my first complete Responsive Landing Page u

More from this blog

T

TheSaurceCode

73 posts

Documenting my journey to becoming a Full Stack Developer through daily blogs, coding challenges, projects, tutorials, and lessons learned. Learn, build, and grow with me