CSSKeyframesRule: appendRule() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since August 2016.

The appendRule() method of the CSSKeyframeRule interface appends a CSSKeyFrameRule to the end of the rules.

Syntax

js
appendRule(rule)

Parameters

rule

A string containing a keyframe rule.

Return value

None (undefined).

Examples

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. Returning the cssRules property would return a CSSRuleList containing one rule.

After appending another rule with appendRule the cssRules property returns a CSSRuleList containing two rules.

css
@keyframes slide-in {
  from {
    transform: translateX(0%);
  }
}
js
let myRules = document.styleSheets[0].cssRules;
let keyframes = myRules[0]; // a CSSKeyframesRule
keyframes.appendRule("to {transform: translateX(100%);}");
console.log(keyframes.cssRules); // a CSSRuleList object with two rules

Specifications

Specification
CSS Animations Level 1
# interface-csskeyframesrule-appendrule

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
appendRule
Chrome – No support
Chrome 1 – 44 (Release date: 2008-12-11)
altname
footnote Removed in 45 and later
altname Alternate name: insertRule
Chrome – Full support
Chrome 41 (Release date: 2015-03-03)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – No support
Firefox 5 – 20 (Release date: 2011-06-21)
altname
altname Alternate name: insertRule
Firefox – Full support
Firefox 21 (Release date: 2013-05-14)
footnote Full support
Opera – No support
Opera 12 – 12.1 (Release date: 2012-06-14)
unknown Support unknown
Opera – No support
Opera 15 – 30 (Release date: 2013-07-02)
altname
footnote Removed in 31 and later
altname Alternate name: insertRule
Opera – Full support
Opera 28 (Release date: 2015-03-10)
footnote Full support
Safari – Full support
Safari 4 (Release date: 2009-06-08)
altname
altname Alternate name: insertRule
Safari – Full support
Safari 9.1 (Release date: 2016-03-21)
footnote Full support
Chrome Android – No support
Chrome Android 18 – 44 (Release date: 2012-06-27)
altname
footnote Removed in 45 and later
altname Alternate name: insertRule
Chrome Android – Full support
Chrome Android 41 (Release date: 2015-03-11)
footnote Full support
Firefox for Android – No support
Firefox for Android 5 – 20 (Release date: 2011-06-21)
altname
altname Alternate name: insertRule
Firefox for Android – Full support
Firefox for Android 21 (Release date: 2013-05-14)
footnote Full support
Opera Android – No support
Opera Android 12 – 12.1 (Release date: 2012-02-25)
unknown Support unknown
Opera Android – No support
Opera Android 14 – 30 (Release date: 2013-05-21)
altname
footnote Removed in 32 and later
altname Alternate name: insertRule
Opera Android – Full support
Opera Android 28 (Release date: 2015-03-10)
footnote Full support
Safari on iOS – Full support
Safari on iOS 3.2 (Release date: 2010-04-03)
altname
altname Alternate name: insertRule
Safari on iOS – Full support
Safari on iOS 9.3 (Release date: 2016-03-21)
footnote Full support
Samsung Internet – No support
Samsung Internet 1 – 4.2 (Release date: 2013-04-27)
altname
footnote Removed in 5 and later
altname Alternate name: insertRule
Samsung Internet – Full support
Samsung Internet 4 (Release date: 2016-03-11)
footnote Full support
WebView Android – No support
WebView Android 4.4 – 44 (Release date: 2013-12-09)
altname
footnote Removed in 45 and later
altname Alternate name: insertRule
WebView Android – Full support
WebView Android 41 (Release date: 2015-03-11)
footnote Full support
WebView on iOS – Full support
WebView on iOS 3.2 (Release date: 2010-04-03)
altname
altname Alternate name: insertRule
WebView on iOS – Full support
WebView on iOS 9.3 (Release date: 2016-03-21)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Uses a non-standard name
Has more compatibility info.