Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
CSS transition-timing-function property
The CSS transition-timing-function property specifies the speed curve of the transition effect. It controls how intermediate values are calculated during a transition, determining whether the animation starts slowly and speeds up, or starts quickly and slows down.
Syntax
selector {
transition-timing-function: value;
}
Possible Values
| Value | Description |
|---|---|
linear |
Constant speed from start to end |
ease |
Slow start, fast middle, slow end (default) |
ease-in |
Slow start, then speeds up |
ease-out |
Fast start, then slows down |
ease-in-out |
Slow start and end, fast middle |
cubic-bezier() |
Custom timing function using cubic bezier curve |
Example: Different Timing Functions
The following example demonstrates various timing functions when you hover over the elements −
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 60px;
background-color: #ff6b6b;
margin: 10px 0;
padding: 15px;
color: white;
font-weight: bold;
transition: width 2s;
border-radius: 5px;
text-align: center;
line-height: 30px;
}
#linear {
transition-timing-function: linear;
}
#ease-in {
transition-timing-function: ease-in;
}
#ease-out {
transition-timing-function: ease-out;
}
#ease-in-out {
transition-timing-function: ease-in-out;
}
div:hover {
width: 300px;
}
</style>
</head>
<body>
<h3>Hover over each box to see the timing effects:</h3>
<div id="linear">Linear</div>
<div id="ease-in">Ease In</div>
<div id="ease-out">Ease Out</div>
<div id="ease-in-out">Ease In Out</div>
</body>
</html>
Four red boxes are displayed with different labels. When you hover over each box, they expand with different speed curves: - Linear: expands at constant speed - Ease In: starts slowly, then accelerates - Ease Out: starts quickly, then decelerates - Ease In Out: starts and ends slowly, faster in the middle
Example: Custom Cubic Bezier
You can create custom timing functions using cubic-bezier() −
<!DOCTYPE html>
<html>
<head>
<style>
.custom-box {
width: 80px;
height: 80px;
background-color: #4CAF50;
margin: 20px;
border-radius: 10px;
transition: transform 1.5s;
transition-timing-function: cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.custom-box:hover {
transform: translateX(200px) rotate(360deg);
}
</style>
</head>
<body>
<p>Hover over the green box for a bouncy custom animation:</p>
<div class="custom-box"></div>
</body>
</html>
A green box appears. When hovered, it moves to the right while rotating with a bouncy, elastic timing effect created by the custom cubic-bezier function.
Conclusion
The transition-timing-function property adds sophistication to animations by controlling their speed curves. Use predefined values for common effects or cubic-bezier() for custom timing behaviors.
Advertisements
