Favorites

Loading Spinner using Emojis - Tutorial

β˜•
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Loader Emojis

A loading spinner doesn't have to be a grey circle. In this tutorial, we'll build a fun spinner from the twelve clock face emojis, so the hands appear to sweep round, using nothing but CSS. Then we'll make a few more variations and make sure they work well for everyone.

Results
Loading…
Clock emoji spinner

How it works

The trick is to animate the content property of a ::before pseudo-element (an extra piece of an element that CSS can create and fill with text). Each keyframe of the animation swaps in a different emoji, so the browser shows one clock face, then the next, and so on, like the frames of a flip book.

Some properties, like content, can't blend smoothly between two values, because there's no "halfway" between two emojis. They're called discrete properties, and they simply switch from one value to the next.

Step 1: choose your emojis

There are twelve clock face emojis, one for each hour:

πŸ•›πŸ•πŸ•‘πŸ•’πŸ•“πŸ•”πŸ••πŸ•–πŸ•—πŸ•˜πŸ•™πŸ•š

They run from 12 o'clock (U+1F55B) round to 11 o'clock (U+1F55A). Any sequence of emojis that looks like movement works well: phases of the moon, a spinning globe, or weather changing. You can find a complete list of emojis over at CharacterCodes.net.

Step 2: the HTML

<div class="loading" role="status">
  <span class="loader" aria-hidden="true"></span>
  <span class="visually-hidden">Loading…</span>
</div>
  • .loader is the element that displays the emoji. aria-hidden="true" stops screen readers (software that reads pages aloud) from reading out each clock face as it changes, such as "twelve o'clock, one o'clock…".
  • The "Loading…" text tells screen reader users what's happening instead. It's hidden visually (see the CSS below), but still read aloud.
  • role="status" makes it a live region, so screen readers announce it when it appears, without interrupting what the person is doing.

Step 3: the CSS

The keyframes

@keyframes clock {
  0%      { content: "πŸ•›"; }
  8.333%  { content: "πŸ•"; }
  16.667% { content: "πŸ•‘"; }
  25%     { content: "πŸ•’"; }
  33.333% { content: "πŸ•“"; }
  41.667% { content: "πŸ•”"; }
  50%     { content: "πŸ••"; }
  58.333% { content: "πŸ•–"; }
  66.667% { content: "πŸ•—"; }
  75%     { content: "πŸ•˜"; }
  83.333% { content: "πŸ•™"; }
  91.667% { content: "πŸ•š"; }
}

Twelve emojis share the animation equally, so each keyframe is 100 Γ· 12 = 8.333% after the last. There's no need for a 100% keyframe: when the animation repeats, it goes straight back to 12 o'clock at 0%.

The spinner

.loader {
  display: inline-block;
  width: 1.2em;
  height: 1.2em;
  font-size: 3rem;          /* the size of the emoji */
  line-height: 1.2;
  text-align: center;
}

.loader::before {
  content: "πŸ•›";             /* shown before the animation starts */
  display: block;
  animation: clock 1.5s step-end infinite;
}

/* Hide text visually, but keep it for screen readers */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
  • 1.5s is how long a full lap of the clock takes, so each hour shows for 0.125 seconds.
  • step-end holds each emoji until the very end of its slot, then jumps straight to the next. Every clock face gets exactly the same amount of time on screen.
  • infinite repeats the animation for as long as the spinner is on the page.
  • The fixed width and height stop the spinner from changing size slightly as the emoji changes, which could make nearby content jiggle.

More emoji spinners

The same technique works with any sequence of emojis, and you can also animate a single emoji with transform. Here are some ideas:

Results
Loading…
Moon phases
Loading…
Spinning globe
Loading…
Flipping hourglass
Loading…
Bouncing dots

Moon phases

@keyframes moon {
  0%    { content: "πŸŒ‘"; }
  12.5% { content: "πŸŒ’"; }
  25%   { content: "πŸŒ“"; }
  37.5% { content: "πŸŒ”"; }
  50%   { content: "πŸŒ•"; }
  62.5% { content: "πŸŒ–"; }
  75%   { content: "πŸŒ—"; }
  87.5% { content: "🌘"; }
}

.loader-moon::before {
  content: "πŸŒ‘";
  animation: moon 1.6s step-end infinite;
}

Eight phases means each keyframe is 100 ÷ 8 = 12.5% apart. The globe works the same way with three emojis (🌍🌎🌏), spaced 33.333% apart.

Flipping hourglass

@keyframes flip {
  0%, 40%  { transform: rotate(0deg); }
  50%, 90% { transform: rotate(180deg); }
  100%     { transform: rotate(360deg); }
}

.loader-hourglass::before {
  content: "⏳";
  animation: flip 2s ease-in-out infinite;
}

This one rotates a single emoji instead of swapping emojis. Holding each position for a while (from 0% to 40%, and from 50% to 90%) creates a pause before each flip, just like turning over a real hourglass.

Bouncing dots

<span class="loader-dots" aria-hidden="true">
  <span>πŸ”΅</span><span>πŸ”΅</span><span>πŸ”΅</span>
</span>
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-0.4em); }
}

.loader-dots span {
  display: inline-block;    /* transforms don't work on inline elements */
  animation: bounce 1.2s ease-in-out infinite;
}

.loader-dots span:nth-child(2) { animation-delay: 0.15s; }
.loader-dots span:nth-child(3) { animation-delay: 0.3s; }

Giving each dot a slightly later animation-delay makes them bounce one after another, like a wave.

Accessibility

Respect reduced motion

Some people find movement on screen uncomfortable, and turn on a "reduce motion" setting on their device. For those visitors, slow the emoji swaps right down and stop the moving spinners, while still showing that something is loading:

@media (prefers-reduced-motion: reduce) {
  .loader::before {
    animation-duration: 6s;     /* a slow, calm tick */
  }

  .loader-hourglass::before,
  .loader-dots span {
    animation: none;            /* still visible, just not moving */
  }
}

Show and hide the spinner properly

A spinner should only be on the page while something is actually loading. Add it when the work starts, and remove it (or add the hidden attribute) when it's finished, so screen readers announce the loading message at the right moment. Press the button to try it:

Results
button.addEventListener('click', async () => {
  button.disabled = true;
  status.textContent = '';
  spinner.hidden = false;           // show the spinner

  await loadTheData();              // your loading code here

  spinner.hidden = true;            // hide it again
  status.textContent = 'Loaded!';   // let everyone know it worked
  button.disabled = false;
});

Good to know: emojis look different on every device, because each operating system draws its own. Test your spinner on a few devices, and pick emojis that still make sense whichever style appears. Also, unlike ordinary text, colour emojis ignore the CSS color property, so you can't recolour them to match your brand.

Customising your spinner

  • Speed: change the animation duration. 1s spins faster, and 3s is more relaxed.
  • Size: change the font-size on .loader. Because the width and height use em units, they grow with it.
  • Inside text or buttons: set font-size: 1em to match the surrounding text, as in this button: Saving…
  • Your own emojis: any sequence works. Count your emojis, divide 100 by that number, and space the keyframes by the result.

Wrapping up

By animating the content property with step-end, you can turn any sequence of emojis into a playful loading spinner with just a few lines of CSS. Keep the emojis hidden from screen readers with a proper "Loading" message instead, give the spinner a fixed size, and calm things down for people who prefer reduced motion.

β˜•
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee