Skip to content

Reading progress bar in WordPress

A blog article topped by a thin bar that fills up as the reader moves through the text.

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

effet-barre-progression-lecture.php
<?php
/**
 * Plugin Name: Forge, Barre de progression de lecture
 * Description: Un article de blog surmonté d’une fine barre qui se remplit à mesure que l’on avance dans la lecture. Ajoute la composition « Barre de progression de lecture » à 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-effet-barre-progression-lecture
 *
pattern.html
<!-- wp:html -->
<article class="efpl" data-efpl aria-labelledby="efpl-titre">
        <span class="efpl__bar" aria-hidden="true"><span class="efpl__fill"></span></span>
        <div class="efpl__body">
          <p class="efpl__eyebrow">Le journal de l’Atelier Grain · Lecture 4 min</p>
          <h2 class="efpl__title" id="efpl-titre">Réussir son espresso à la maison</h2>
          <p class="efpl__lead">Pas besoin d’une machine à mille euros : quatre réglages font toute la différence entre un café amer et une tasse ronde, sucrée et crémeuse.</p>
          <h3 class="efpl__subtitle">1. Une mouture fraîche et fine</h3>
          <p class="efpl__text">Le café moulu perd la moitié de ses arômes en un quart d’heure. Moulez juste avant l’extraction, avec un moulin à meules plutôt qu’à hélices : la mouture doit ressembler à du sucre glace un peu granuleux, régulière d’un bout à l’autre.</p>
          <h3 class="efpl__subtitle">2. La bonne dose</h3>
          <p class="efpl__text">Pesez 18 grammes de café pour un double espresso. Répartissez la mouture dans le porte-filtre en tapotant les bords, puis tassez bien à plat, d’une pression ferme et constante : un tassage penché crée des chemins préférentiels et l’eau file sans extraire.</p>
          <h3 class="efpl__subtitle">3. Le temps d’extraction</h3>
script.js
(() => {
  if (!document.querySelector(".efpl")) return;
  // Firefox does not support view timelines yet: replay the same range by hand.
  if (!CSS.supports("animation-timeline: view()")) {
    const reduce = matchMedia("(prefers-reduced-motion: reduce)");
    document.querySelectorAll("[data-efpl]").forEach((root) => {
      const bar = root.firstElementChild;
      const fill = bar.firstElementChild;
      const update = () => {
        bar.style.display = reduce.matches ? "" : "block";
        // "contain" range: from the article filling the viewport to its end reaching the viewport bottom.
        const box = root.getBoundingClientRect();
style.css
:root {
  --efpl-bg: #ffffff;
  --efpl-border: #e7e5e4;
  --efpl-text: #1c1917;
  --efpl-body: #44403c;
  --efpl-track: #f5f5f4;
  --efpl-fill-start: #ea580c;
  --efpl-fill-end: #9a3412;
  --efpl-accent: #9a3412;
  --efpl-on-accent: #ffffff;
  --demo-effet-barre-progression-lecture-bg: #f5f5f4;
  --demo-effet-barre-progression-lecture-text: #1c1917;

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

Visual effects components in WordPress
  • Cards that fade in as they enter the screen, one after another in each row, without a line of JavaScript and with a static fallback.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A translucent card with a saturated blur whose sharper edge refracts the colourful shapes drifting behind it, with an opaque fallback when transparency is reduced.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A help block shaped like a conversation: bubbles, three animated typing dots and clickable quick replies that show your answers to frequent questions, frozen under prefers-reduced-motion.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A paragraph whose words turn from grey to full ink, one by one, as the page scrolls, in pure CSS with a plain-text fallback.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Four offset, translucent sine waves gently roll along the bottom of a section, each at its own pace.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component