@keyframes
Quick Summary for @keyframes
The @keyframes CSS at-rule controls the intermediate steps in a CSS animation sequence by defining styles for keyframes (or waypoints) along the animation sequence. This gives more control over the intermediate steps of the animation sequence than transitions.
Code Usage for @keyframes
@keyframes slidein {   from {     transform: translateX(0%);   }    to {     transform: translateX(100%);   } } 
More Details for @keyframes

@keyframes

The @keyframes CSS at-rule controls the intermediate steps in a CSS animation sequence by defining styles for keyframes (or waypoints) along the animation sequence. This gives more control over the intermediate steps of the animation sequence than transitions.

Syntax

@keyframes slidein {   from {     transform: translateX(0%);   }    to {     transform: translateX(100%);   } } 

Values

<custom-ident>

A name identifying the keyframe list. This must match the identifier production in CSS syntax.

from

A starting offset of 0%.

to

An ending offset of 100%.

<percentage>

A percentage of the time through the animation sequence at which the specified keyframe should occur.

Description

JavaScript can access the @keyframes at-rule with the CSS object model interface CSSKeyframesRule.

To use keyframes, create a @keyframes rule with a name that is then used by the animation-name property to match an animation to its keyframe declaration. Each @keyframes rule contains a style list of keyframe selectors, which specify percentages along the animation when the keyframe occurs, and a block containing the styles for that keyframe.

You can list the keyframe percentages in any order; they will be handled in the order they should occur.

Valid keyframe lists

If a keyframe rule doesn't specify the start or end states of the animation (that is, 0%/from and 100%/to), browsers will use the element's existing styles for the start/end states. This can be used to animate an element from its initial state and back.

Properties that can't be animated in keyframe rules are ignored, but supported properties will still be animated.

Resolving duplicates

If multiple keyframe sets exist for a given name, the last one encountered by the parser is used. @keyframes rules don't cascade, so animations never derive keyframes from more than one rule set.

If a given animation time offset is duplicated, all keyframes in the @keyframes rule for that percentage are used for that frame. There is cascading within a @keyframes rule if multiple keyframes specify the same percentage values.

When properties are left out of some keyframes

Properties that aren't specified in every keyframe are interpolated if possible — properties that can't be interpolated are dropped from the animation. For example:

@keyframes identifier {   0% { top: 0; left: 0; }   30% { top: 50px; }   68%, 72% { left: 50px; }   100% { top: 100px; left: 100%; } } 

Here, the top property animates using the 0%, 30%, and 100% keyframes, and left animates using the 0%, 68%, 72% and 100% keyframes.

When a keyframe is defined multiple times

If a keyframe is defined multiple times but not all affected properties are in each keyframe, all values specified in these keyframes are considered. For example:

@keyframes identifier {   0% { top: 0; }   50% { top: 30px; left: 20px; }   50% { top: 10px; }   100% { top: 0; } } 

In this example, at the 50% keyframe, the values used are top: 10px and left: 20px.

Cascading keyframes are supported starting in Firefox 14.

!important in a keyframe

Declarations in a keyframe qualified with !important are ignored.

@keyframes important1 {   from { margin-top: 50px; }   50%  { margin-top: 150px !important; } /* ignored */   to   { margin-top: 100px; } }  @keyframes important2 {   from { margin-top: 50px;          margin-bottom: 100px; }   to   { margin-top: 150px !important; /* ignored */          margin-bottom: 50px; } } 

Formal syntax

@keyframes <keyframes-name> {   <keyframe-block-list> }

where <keyframes-name> = <custom-ident> | <string><keyframe-block-list> = <keyframe-block>+

where <keyframe-block> = <keyframe-selector># { <declaration-list> }

where <keyframe-selector> = from | to | <percentage>

Examples

CSS animation examples

See Using CSS animations for examples.

Specifications

Specification
CSS Animations Level 2 # keyframes

See also

Using CSS animations AnimationEvent

Last modified: Aug 12, 2021, by MDN contributors

Select your preferred language English (US)DeutschEspañolFrançais日本語한국어Português (do Brasil)中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
Don't look to be the next Facebook, try to solve a real problem instead.
Unknown
Random CSS Property

grid-row-end

The grid-row-end CSS property specifies a grid item's end position within the grid row by contributing a line, a span, or nothing (automatic) to its grid placement, thereby specifying the inline-end edge of its grid area.
grid-row-end css reference