W3cubDocs

/Web APIs

CSSKeyframesRule

The CSSKeyframesRule interface describes an object representing a complete set of keyframes for a CSS animation. It corresponds to the contents of a whole @keyframes at-rule.

CSSRule CSSKeyframesRule

Instance properties

Inherits properties from its ancestor CSSRule.

CSSKeyframesRule.name

Represents the name of the keyframes, used by the animation-name property.

CSSKeyframesRule.cssRules Read only

Returns a CSSRuleList of the keyframes in the list.

Instance methods

Inherits methods from its ancestor CSSRule.

CSSKeyframesRule.appendRule()

Inserts a new keyframe rule into the current CSSKeyframesRule. The parameter is a string containing a keyframe in the same format as an entry of a @keyframes at-rule. If it contains more than one keyframe rule, a DOMException with a SYNTAX_ERR is thrown.

CSSKeyframesRule.deleteRule()

Deletes a keyframe rule from the current CSSKeyframesRule. The parameter is the index of the keyframe to be deleted, expressed as a string resolving as a number between 0% and 100%.

CSSKeyframesRule.findRule()

Returns a keyframe rule corresponding to the given key. The key is a string containing an index of the keyframe to be returned, resolving to a percentage between 0% and 100%. If no such keyframe exists, findRule returns null.

Example

The CSS includes a keyframes at-rule. This will be the first CSSRule returned by document.styleSheets[0].cssRules. myRules[0] returns a CSSKeyframesRule object.

css

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

  to {
    transform: translateX(100%);
  }
}

js

let myRules = document.styleSheets[0].cssRules;
let keyframes = myRules[0]; // a CSSKeyframesRule

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
CSSKeyframesRule 311–31 12 485–48 10 1815–1812.1–1512–12.1 9.14–9.1 4.4.31–4.4.3 3118–31 485–48 1814–1812.1–1412–12.1 9.33.2–9.3 2.01.0–2.0
appendRule 411–45 12 215–21 10 2815–3112–15 9.14 414.4–45 4118–45 215–21 2814–3212–14 9.33.2 4.01.0–5.0
cssRules 1 12 5 10 12 4 4.4 18 5 12 3.2 1.0
deleteRule 1 12 5 10 12 4 4.4 18 5 12 3.2 1.0
findRule 1 12 5 10 12 4 4.4 18 5 12 3.2 1.0
length No No 109 No No 17 No No 109 No 17 No
name 1 12 5 10 12 4 4.4 18 5 12 3.2 1.0

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CSSKeyframesRule