Skip to content

Animated counters in WordPress

Four key figures in cards that count up from zero to their value when the section scrolls into view, with icon, unit and label.

Here is an excerpt of this component's code in WordPress. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in WordPress

pattern.html
<!-- wp:html -->
<section class="counters" aria-labelledby="counters-title" data-counters>
        <div class="counters__head">
          <p class="counters__eyebrow">Bilan 2025</p>
          <h2 class="counters__title" id="counters-title">Une année de seconde main, en chiffres</h2>
          <p class="counters__lead">Les six recycleries du réseau collectent, réparent et revendent ce que d'autres auraient jeté, avec des équipes en insertion.</p>
        </div>
        <dl class="counters__list">
          <div class="counters__item">
            <dt class="counters__label">d'objets réemployés plutôt que jetés</dt>
            <dd class="counters__value">
              <span class="counters__icon" aria-hidden="true"><svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M7 19H4.5a2 2 0 0 1-1.7-3l2.6-4.5M11 19h8.5a2 2 0 0 0 1.7-3l-1.3-2.2M14.5 5.5 12.9 2.8a2 2 0 0 0-3.4 0L7.6 6"/><path d="m9 16-2 3 2 3M17.5 10.5l2.4-1.2.3 2.7M5.6 9.4 3 8.6l.7 2.6"/></svg></span>
script.js
(() => {
  if (!document.querySelector(".counters")) return;
  document.querySelectorAll("[data-counters]").forEach((root) => {
    // The final figures are already in the HTML: without animation, nothing needs to change.
    if (matchMedia("(prefers-reduced-motion: reduce)").matches || !("IntersectionObserver" in window)) return;
    const counters = [...root.querySelectorAll("[data-count]")];
    const formats = counters.map((el) => {
      const decimals = Number(el.dataset.decimals || 0);
      return new Intl.NumberFormat("fr-FR", { minimumFractionDigits: decimals, maximumFractionDigits: decimals });
    });
    const draw = (progress) => {
      counters.forEach((el, i) => {
stats-compteurs-animes.php
<?php
/**
 * Plugin Name: Forge, Compteurs animés
 * Description: Quatre chiffres clés en cartes, qui défilent de zéro à leur valeur quand la section entre à l'écran, avec icône, unité et libellé. Ajoute la composition « Compteurs animés » à l'éditeur de blocs.
 * Version: 1.0.0
 * Requires at least: 6.6
 * Requires PHP: 8.1
 * Author: Forge
 * License: GPL-2.0-or-later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: forge-stats-compteurs-animes
 *
style.css
:root {
  --counters-text: #2a160a;
  --counters-muted: #6b4a35;
  --counters-accent: #c2410c;
  --counters-pill: #ffedd5;
  --counters-pill-text: #9a3412;
  --counters-card: #ffffff;
  --counters-line: #fed7aa;
  --demo-stats-compteurs-animes-bg: #fff7ed;
  --demo-stats-compteurs-animes-text: #2a160a;
}

Free component: copy it freely, including for commercial projects.

Statistics components in WordPress
  • A client area page for a small business website: sidebar, four metrics (visits, requests, reply rate and reply time) with their change, an SVG line chart per period and a filterable table of the latest messages, with no chart library.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Three semicircle gauges whose needle swings to the value, with figure, label and source readable as text, in pure CSS.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A row of guarantees (ten-year insurance, free quote, call-out within 24 hours, RGE and Qualibat labels) that reassures visitors right below the call to action.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Four tinted paper cards pinned askew with tape on a dotted background: each figure of the venue's story has its line drawing, its title and its sentence.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Four key figures in a row, each with its caption, separated by thin rules.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component