JavaScript

Calculate Reading Time

by @admin
10h ago
Apr 28, 2026
Public
Estimates the reading time of a block of text based on an average adult reading speed (default 200 words per minute). Strips HTML tags before counting to handle rich-text content. Returns the result in minutes, rounded up, so a short article always shows at least "1 min read".
JavaScript
function readingTime(text, wordsPerMin = 200) {
  const clean    = text.replace(/<[^>]+>/g, '');
  const wordCount = clean.trim().split(/\s+/).filter(Boolean).length;
  const minutes  = Math.ceil(wordCount / wordsPerMin);
  return { minutes, wordCount, label: `${minutes} min read` };
}

// Usage
const article = document.querySelector('article').innerHTML;
const { label, wordCount } = readingTime(article);
document.querySelector('.reading-time').textContent = label;
// e.g. "4 min read"
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.