or, in shorthand:
transition:
color 2s,
transform 300ms 1s;
transition-duration
transition-delay
transition-property
transition-property: color, transform;
transition-duration: 2s, 300ms;
transition-delay: 0, 1s; | transform functions (classic) | Equivalent individual transform properties (modern) |
|---|---|
transform: translateX(30px); | translate: 30px 0; |
transform: translateY(30px); | translate: 0 30px; |
transform: scaleX(2); | scale: 2 1; |
transform: scaleY(2); | scale: 1 2; |
transform: rotate(30deg); | rotate: 30deg; |
transform: skew(20deg, 30deg); | transform: skew(20deg, 30deg); |
transform describes what an element looks like in a particular state.
transition describes how the browser gets the element from one state to another.
.animated-div {
animation: black-to-white 1s linear 1;
}
@keyframes black-to-white {
0% { background: black; }
100% { background: white; }
}
.animated-div {
animation: black-to-white 1s linear 2s 2;
}@keyframes black-to-white {
from {
background: black;
color: white;
}
to {
background: white;
color: black;
}
}@keyframes black-to-white {
0% { color: black; }
50% { color: grey; }
100% { color: white; }
}you can add prefers-reduced-motion so your animations don't run/trigger symptoms for those with visual sensitivities or neurological conditions (epilepsy, migraines, ADHD, etc.) who have turned animations off in their OSs/browsers