Pseudo-elements in the Web Animations API

The Web Animations API, including calls like el.animate(), needs a DOM element reference to target. Pseudo-elements have no such direct reference, but the API itself provides a way to address them, as Dan Wilson covers.

const logo = document.getElementById('logo');

logo.animate({ opacity: [0, 1] }, {
  duration: 100,
  pseudoElement: '::after'
});

Dan's write-up notes that ::marker is supported. That came up recently during work on the List Style Recipes page, so the WAAPI and @keyframes were tried out on both a ::marker and an ::after element.

At first it looked as though the WAAPI wasn't working on ::after. Dan pointed out that a transform can't apply to an element that is display: inline; switching it to inline-block made it work. One finding from the test: @keyframes don't appear to work on ::marker elements in Firefox. Hopefully that gets fixed, along with Chrome and Safari support for ::marker arriving as soon as possible.