How to Make Basic Transition Animations using CSS

How to Make Basic Transition Animations using CSS

In this CSS transition tutorial, we are going to learn how to make some basic transition animations using CSS. If you are working with web technologies like CSS, HTML, and JavaScript, it's important to have some basic knowledge about CSS animations and transitions.

If you are working with web technologies like CSS, HTML, and JavaScript, it's important to have some basic knowledge about CSS animations and transitions.

In this article we are going to learn how to make some basic transition animations using CSS.

How to animate an element with basic transition on hover

In this example, we will make the opacity of an element change when a user hovers or mouses over the element.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Static Template</title>
  </head>
  <style>
    .elem {
      background: blueviolet;
      width: 300px;
      height: 150px;
    }
    .elem:hover {
      opacity: 0.5;
    }
  </style>
  <body>
    <div class="elem"></div>
  </body>
</html>

This is a simple transition that can be triggered when we hover over the element. We can add more than one transition that will run at the same time.

Let's add a scale transform property to add scale transition to the element.

 .elem:hover {
      transform: scale(1.1);
    }

But the transition doesn't seem to be smooth, because we didn't define the duration of the transition or use any timing function.

If we add the transition property, it will make the element move more smoothly.

 .elem {
      background: blueviolet;
      width: 300px;
      height: 150px;
      margin: 20px auto;
      transition: 500ms linear; 
    }

Let's break down how the transition property works:

  transition: 500ms linear;
  • 500ms: the duration of the transition in milliseconds
  • linear: the timing-function
div {
    transition: <property> <duration> <timing-function> <delay>;
}

We can add more options like below (examples from the MDN):

#delay {
  transition-property: font-size;
  transition-duration: 4s;
  transition-delay: 2s;
}

So what's this code doing?

  • transition-property: the property you want to animate. It can be any CSS element like background, height, translateY, translateX, and so on.
  • transition-duration: the duration of the transition
  • transition-delay: the delay before the transition starts

You can learn more about the different uses of transition in CSS here.

css web-development programming developer

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Hire CSS Developer

Want to develop a website or re-design using CSS Development? We build a website and we implemented CSS successfully if you are planning to **[Hire CSS Developer](https://hourlydeveloper.io/hire-dedicated-css-developer/ "Hire CSS Developer")**...

Why Web Development is Important for your Business

With the rapid development in technology, the old ways to do business have changed completely. A lot more advanced and developed ways are ...

Important Reasons to Hire a Professional Web Development Company

    You name the business and I will tell you how web development can help you promote your business. If it is a startup or you seeking some...

Software Developer vs Web Developer | Difference Web Developer & Software Developer

Software Developer vs Web Developer | Difference Web Developer & Software Developer | Software development and web development are normally used interchangeably. Although both include development, a software developer has different responsibilities from that of a web developer.

Developing for the Mobile-Web: Part 1 — CSS Media Queries

Developing our web pages for the mobile web has never been more important than it is now. I grew up in the early stages of the internet.