How to automatically calculate and display article reading time with Webflow CMS

Written by
John Doe
公開日
2026-01-27

table of contents

Some people use Webflow's CMS to manage blog postsI want to automatically display “This article can be read in ◯ minutes” I think there are many people who think that.

This time How to automatically calculate article reading time using JavaScript and display it dynamically on Webflow pages I will explain it to you.

I'll explain it in detail, including the process of actually implementing it through trial and error, so be sure to check it out!

1. Step 1: Review the article structure

First, check how the main text of the article is arranged in Webflow's CMS.

Necessary elements:

  • Includes the main text of the article .article-content Let's check out the rich text blocks in the class. This is the part that shows the main content of the article.

1-1. Setup procedure in Webflow

  1. Open Webflow's Designer (design editor)
  2. Go to the CMS collection page(blog post template pages, etc.)
  3. Select a rich text block to display the article text
  4. “Class” .article-content Set to(check only if you already have one)

1-2. How to check the elements in the article text

  1. Publish the page or open preview
  2. Open the browser's development tools (F12 key)
  3. On the Elements tab .article-content Search
  4. Check if the text of the article is correct

Also, display the reading time .reading-time-container It's called Div Place the element within the page. This element is for dynamically inserting reading times calculated using JavaScript.

First, in Webflow design mode .reading-time-container Add it and place it in an appropriate position. For example, something just below the article title is appropriate.

Development tools (F12) is used to create the main text of the article .article-content Let's check that it's applied to.

console.log("記事本文:", document.querySelector(".article-content"));

run this code in the console,null Instead, it's OK if the rich text block HTML is displayed.

2. Step 2: Calculate reading time with JavaScript

To dynamically display read time on Webflow pages, use JavaScript.

To calculate reading time,Generally read about 500 characters per minute We will adopt this assumption.

2-1. initial implementation(basic reading time calculation)

This script is Webflow's “Before </body> Tags” area If you add to, when the page loads Calculate the number of characters in the main text of the article and read it time .reading-time-container Insert into You can do it.

document.addEventListener("DOMContentLoaded", function () {
    let articleContent = document.querySelector(".article-content");
    let readTimeContainer = document.querySelector(".reading-time-container");

    if (articleContent && readTimeContainer) {
        let text = articleContent.innerText.trim();
        let charCount = text.length;
        let readingSpeed = 500;
        let readingTime = Math.ceil(charCount / readingSpeed);
        readTimeContainer.textContent = `この記事は約 ${readingTime} 分で読めます。`;
    }
});
    }
});

3. Step 3: Address Webflow CMS load delays

In Webflow Since CMS data is loaded asynchronously, the article text hasn't been loaded yet when the script is executed There is something.

To resolve this issue,A process that waits for up to 5 seconds (100ms x 50 times) for an article to load I will add it.

3-1. Revised JavaScript (optimized version for Webflow)

document.addEventListener("DOMContentLoaded", function () {
    let articleContent = document.querySelector(".article-content");
    let readTimeContainer = document.querySelector(".reading-time-container");

    if (articleContent && readTimeContainer) {
        let text = articleContent.innerText.trim();
        let charCount = text.length;
        let readingSpeed = 500;
        let readingTime = Math.ceil(charCount / readingSpeed);
        readTimeContainer.textContent = `この記事は約 ${readingTime} 分で読めます。`;
    }
});
        readTimeContainer.style.display = "block";
        readTimeContainer.style.visibility = "visible";
        console.log("✅ 読了時間が設定されました:", readTimeContainer.textContent);
    }

    function observeContentChanges(articleContent, readTimeContainer) {
        let observer = new MutationObserver(() => {
            let text = articleContent.innerText.trim();
            let charCount = text.length;
            if (charCount > 0) {
                updateReadingTime(charCount, readTimeContainer);
            }
        });

        observer.observe(articleContent, { childList: true, subtree: true, characterData: true });
        observer.observe(readTimeContainer, { childList: true, subtree: true, characterData: true });
    }
});

4. Step 4: Debug when the read time is not displayed

4-1. .reading-time-container I can't find it

Check if the element is present by running the following command in the console.

console.log(document.querySelector(".reading-time-container"));

If null, the element doesn't exist on the page So, on Webflow .reading-time-container Please add it correctly.

4-2. Make sure it's not hidden in CSS

Run the following code and test whether the elements are displayed correctly.

document.querySelector(".reading-time-container").style.display = "block";document.querySelector(".reading-time-container").style.visibility = "visible";

4-3. Confirm retrieval of article text

console.log(document.querySelector(".article-content")?.innerText);

If the article text can be obtained here, there is a high possibility that the script is working properly.

5. Summary

To automatically display the reading time in Webflow CMS, calculate the number of characters in the article using JavaScript
Wait up to 5 seconds to support Webflow's delayed loading setInterval Make use of
.reading-time-container Make sure the settings are correct and check the effects of CSS
Use MutationObserver to respond even when the content of an article changes

Relation

関連記事

This is some text inside of a div block.

Full record of building the self-hosted AI agent “Moltworker” on Cloudflare

This is some text inside of a div block.
7 min read
This is some text inside of a div block.

I dissected all pages of the “Textbook on Psychological Manipulation” that arrived in the mail -- the invisible design of sales letters deciphered with behavioral economics

This is some text inside of a div block.
7 min read
This is some text inside of a div block.

Claude Code User Guide 2025 Latest Edition/From Introduction to Application

This is some text inside of a div block.
7 min read
This is some text inside of a div block.

Google's NotebookLM is finally integrated with Gemini, and AI research tools enter a new era

This is some text inside of a div block.
7 min read
This is some text inside of a div block.

Will Google's new weapon “Titans” dramatically change AI's memory? Approaching the mystery of long-term memory that surpasses Transformers

This is some text inside of a div block.
7 min read
This is some text inside of a div block.

Thorough explanation of how to use Google Antigravity | Towards an age where anyone can develop apps with AI

This is some text inside of a div block.
7 min read

Let's start with a free consultation

I'm very sorry. Our resources are limited, and in order to provide high quality services to each company, we are currently offering this special condition (full refund guarantee+free consultation), limited to [first 5 companies per month].

Furthermore, only for those who have applied for a free consultation, we will give you a free “competitor site analysis & improvement proposal report” usually worth 50,000 yen only for those who have applied for a free consultation.

There is a possibility that the slots will fill up quickly, so please apply as soon as possible.

I agree to the privacy policy and first conduct a free consultation
Thank you! Your submission has been received!
Oops! Something went long while appearing the form.