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
Usage of CSS transition-timing-function property
The CSS transition-timing-function property controls the speed curve of a transition effect. It determines how the transition progresses over time, allowing you to create smooth, natural-looking animations or more dramatic effects.
Syntax
selector {
transition-timing-function: value;
}
Possible Values
| Value | Description |
|---|---|
linear |
Constant speed throughout the transition |
ease |
Default. Slow start, fast middle, slow end |
ease-in |
Slow start, gradually speeds up |
ease-out |
Fast start, gradually slows down |
ease-in-out |
Slow start and end, fast middle |
cubic-bezier() |
Custom timing function using cubic bezier curve |
Example: Comparing Timing Functions
The following example demonstrates different timing functions when hovering over elements −
<!DOCTYPE html>
<html>
<head>
<style>
.container {
margin: 20px 0;
}
.box {
width: 100px;
height: 50px;
background-color: #3498db;
color: white;
display: flex;
align-items: center;
justify-content: center;
margin: 10px 0;
transition: width 2s;
font-size: 12px;
}
.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;
}
.box:hover {
width: 300px;
background-color: #e74c3c;
}
</style>
</head>
<body>
<h3>Hover over each box to see timing effects:</h3>
<div class="box linear">linear</div>
<div class="box ease-in">ease-in</div>
<div class="box ease-out">ease-out</div>
<div class="box ease-in-out">ease-in-out</div>
</body>
</html>
Four blue boxes are displayed vertically. When hovered, each box expands to the right and turns red, but with different speed curves: - Linear: constant speed expansion - Ease-in: starts slow, speeds up - Ease-out: starts fast, slows down - Ease-in-out: slow start and end, fast middle
Example: Custom Timing with Cubic Bezier
You can create custom timing functions using cubic-bezier values −
<!DOCTYPE html>
<html>
<head>
<style>
.custom-box {
width: 80px;
height: 80px;
background-color: #9b59b6;
margin: 20px 0;
transition: transform 1.5s;
transition-timing-function: cubic-bezier(0.68, -0.55, 0.265, 1.55);
border-radius: 10px;
}
.custom-box:hover {
transform: translateX(200px) rotate(360deg);
}
</style>
</head>
<body>
<p>Hover for a bounce-like custom timing effect:</p>
<div class="custom-box"></div>
</body>
</html>
A purple rounded square that, when hovered, slides to the right while rotating with a bouncy, elastic timing effect due to the custom cubic-bezier function.
Conclusion
The transition-timing-function property is essential for creating natural-looking animations. Use predefined values like ease-in for common effects, or cubic-bezier() for custom timing curves that match your design needs.
Advertisements
