Animation
should respect the prefers-reduced-motion media query for users sensitive to motion.
Keyframes
CSS keyframes are a feature of CSS animations that allow you to define a set of styles at various points in an animation timeline. Keyframes are used in conjunction with the @keyframes rule to specify the intermediate steps and styles that make up an animation.
Here's an example of how to define and use CSS keyframes:
-
Defining Keyframes:
To define keyframes, you use the
@keyframesrule followed by a name for the animation and a block of CSS rules that represent the intermediate styles at different points in the animation timeline. Each keyframe is defined using a percentage value or a keyword (fromorto).@keyframes example-animation {
0% {
/* Styles at the beginning of the animation */
}
50% {
/* Styles at the middle of the animation */
}
100% {
/* Styles at the end of the animation */
}
}
```
In the example above, `example-animation` is the name given to the keyframes. The `0%` keyframe represents the starting point of the animation, the `50%` keyframe represents the middle point, and the `100%` keyframe represents the end point. -
Applying Keyframes to an Element:
Once you have defined the keyframes, you can apply them to an element using the
animation-nameproperty, along with other animation-related properties such asanimation-duration,animation-timing-function, andanimation-iteration-count..example-element {
animation-name: example-animation;
animation-duration: 2s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
}
```
In the example above, the `.example-element` class is assigned the `example-animation` keyframes using the `animation-name` property. The animation will run for 2 seconds, have an ease-in-out timing function, and repeat infinitely.
CSS keyframes provide a powerful way to create animations by defining intermediate styles at different points in time. By combining keyframes with other animation properties, you can control the timing, duration, and appearance of animations on your web page.
animation

- animate.style
- https://animxyz.com/
- https://stackblitz.com/edit/wizdm-aos-hgurob?file=src%2Fapp%2Fhome%2Fhome.component.html
- https://www.freecodecamp.org/news/beautiful-page-transitions-in-angular/
- https://useanimations.com/
- https://github.com/lindelof/awesome-web-effect
- https://polypane.app/css-3d-transform-examples/
- full screen carousel animation
Transitions: Transitions are CSS animations that occur when a property changes over time. They can be used to add subtle or dramatic effects to user interface elements, such as hover effects, dropdown menus, and button states. For example, a transition can be used to smoothly animate a button's background color when the user hovers over it, giving visual feedback and making the interaction more engaging.
Transformations: Transformations are CSS properties that modify the appearance of an element by changing its size, position, or shape. They can be used to create complex visual effects, such as rotating, scaling, or skewing elements. For example, a transformation can be used to create a flip card animation that shows a different side of the card when the user clicks on it.
Navigation menus: Transitions and transformations can be used to create engaging navigation menus that respond to user interaction. For example, a menu can be designed to slide into view when the user clicks on a button, or to fade in and out when the user scrolls on the page.
Interactive elements: Transitions and transformations can be used to create interactive elements that respond to user input, such as sliders, toggles, and dropdown menus. For example, a slider can be designed to smoothly animate as the user drags the slider handle, providing visual feedback and making the interaction more engaging.
Page transitions: Transitions and transformations can be used to create page transitions that enhance the user experience and create a seamless flow between pages. For example, a page can be designed to slide out of view as the user clicks on a link, or to fade in and out when the user scrolls up or down the page.
to keyword
CSS keyframe animations are powerful for creating animations on your webpages. To define an animation, you'll need two parts:
-
@keyframes rule: This rule defines the animation itself, specifying the start and end states (keyframes) and any intermediate styles along the animation timeline.
-
Animation properties: These properties are applied to the element you want to animate, referencing the animation name defined in the
@keyframesrule and additional properties like duration, timing function, etc.
Here's a basic structure of a CSS keyframe animation:
/* 1. Define the animation with keyframes */
@keyframes animationName {
from { /* Styles at the beginning (0%) */
transform: translateX(0); /* Example: start from position X=0 */
}
to { /* Styles at the end (100%) */
transform: translateX(100px); /* Example: move to X=100px */
}
}
/* 2. Apply the animation to an element */
.myElement {
animation: animationName 2s ease-in-out infinite; /* Example usage */
}
Explanation:
- We define an animation named
animationNameusing the@keyframesrule. - Inside the
@keyframesrule, we have two keyframes:from(0%) andto(100%). - The
fromkeyframe sets the initial styles, in this case, we usetransform: translateX(0)for demonstration. You can define any CSS properties here. - The
tokeyframe sets the final styles, where we usetransform: translateX(100px)to move the element 100 pixels to the right. - In the second part, we apply the animation to the element with class
.myElement.animation: animationName- This references the animation name defined earlier.2s- This sets the animation duration to 2 seconds.ease-in-out- This defines the timing function that controls the animation speed at different stages.infinite- This makes the animation repeat indefinitely.
Remember: This is a basic example. You can define multiple keyframes within the @keyframes rule to create more complex animations with various styles at different points in time. You can also use other animation properties like animation-delay and animation-iteration-count to control the animation behavior.