0% completed
CSS transitions let you smoothly change properties over a set amount of time. When an element changes state—like when a user hovers over it—the transition property tells the browser how long and in what manner the change should happen.
Transitions are defined using three main values:
selector { transition: property duration timing-function; }
Explanation:
background-color
or width
).0.5s
for half a second).linear
– Even speed from start to finish.ease
– Starts slow, speeds up, and then slows down.ease-in
– Starts slow.ease-out
– Ends slow.ease-in-out
– Starts and ends slow.In this example, a button smoothly changes its background color over 0.5 seconds when hovered over.
Explanation:
#4caf50
).#45a049
).transition
property makes the background color change smoothly over 0.5 seconds with an "ease" timing function.In this example, a box changes both its width and its background color smoothly when hovered. This shows how you can animate more than one property at the same time.
Explanation:
width
changes over 0.5 seconds with an ease-in-out timing function.background-color
changes over 0.5 seconds with a linear timing function.By using the transition property, you can enhance user interactions with smooth changes. This not only improves the aesthetics of your website but also provides clear visual feedback when users interact with elements.
.....
.....
.....