Sprites on the Web In 2015, Twitter's development team needed to replace the "favorite" star icon with a "like" heart icon, but the complex 16-element animation for the heart was too resource-intensive for low-end mobile devices. To solve this, they used a sprite technique borrowed from video games, where all animation frames are combined into a single image strip and displayed one at a time. The article explains how to implement this using CSS properties like `object-fit`, `object-position`, and the `steps()` timing function to create efficient, frame-based animations. In 2015, back when Twitter was still Twitter, their dev team had a problem. In those early days, tweets could be “favourited” by clicking a little “⭐” icon. The product team wanted to migrate to “liking” tweets, Facebook-style, with a “❤️”. As part of this update, their designers created this lovely animation: This looks super nice, but there’s kind of a lot going on in there; by my count, there are 16 separate elements all animating at the same time 14 particles, the popping circle, the heart . Twitter’s web app needed to run on very low-end mobile devices, so it wasn’t feasible to create this procedurally using DOM nodes. Instead, they decided to borrow a technique from video games: sprites. The basic idea with a sprite is that we create a single image that contains each individual frame of an animation in a long strip. Then, we display each frame for a fraction of a second, like a roll of film sliding through an oldschool film projector: This technique has been around for decades; I vaguely remember learning how to do this with background-position in the early 2000s. Fortunately, modern CSS has given us some great new options for implementing sprites In this blog post, I’ll show you the best way I’ve found to work with sprites in CSS and share some of the use cases I’ve discovered. We’ll also talk about some of the trade-offs, to see when we shouldn’t use sprites. Link to this headingBasic implementation First thing’s first, we need an asset Let’s use a gold trophy sprite I created a few years ago: To produce the illusion that the fire is flickering, I drew five different versions of the blue flames. These frames are stacked side-by-side in a single image known as a “spritesheet”: Here’s the fundamental strategy: we’ll create an