Skip to content
Code & Tools

A Tiny JavaScript Helper for Reading Time

Theo Marsh
1 min read
295
Cover photo for “A Tiny JavaScript Helper for Reading Time”

Reading-time estimates are simple arithmetic dressed up as a feature. Here is the whole thing, small enough to paste anywhere.

Constraints are underrated. A fixed word count, a single typeface, or a two-colour palette forces decisions that an open brief lets you postpone forever.

reading-time.js
export function readingTime(text, wpm = 200) {
  const words = text
    .replace(/<[^>]+>/g, ' ')
    .trim()
    .split(/\s+/)
    .filter(Boolean).length;
  return Math.max(1, Math.ceil(words / wpm));
}

const minutes = readingTime(document.querySelector('article').innerHTML);
console.log(`${minutes} min read`);
JavaScript UTF-8·LF·11 lines

Every studio accumulates habits it never chose. Once a year we list them and ask whether each one still earns its place.

We schedule unstructured time on purpose. Some of our best ideas started as an afternoon with no plan and a stack of old magazines.

Feedback lands better when it describes the effect rather than the fix. “I lost track here” is more useful than “move this paragraph”.

10
Continue reading

Related posts

All posts
Conversation

Comments · 10

Posting as guest · Sign in
  1. Maya Lindqvist ·

    I tried this on a client project last month and it saved us at least two review rounds.

    1. Theo Marsh Author ·

      Portra 400 for most of them, and one roll of HP5 for the evening shots.

      1. Theo Marsh Author ·

        Yes! Same experience here.

  2. Nils Berg ·

    I tried this on a client project last month and it saved us at least two review rounds.

  3. Jonah Reyes ·

    Great list. Adding two of these to my reading pile right now.

  4. Maya Lindqvist ·

    We adopted the no-email-before-ten rule after your last post. Our mornings are so much calmer.

  5. Clara Fontaine ·

    We adopted the no-email-before-ten rule after your last post. Our mornings are so much calmer.

    1. Theo Marsh Author ·

      Glad it helped. The second pass is where it really clicks.

  6. Clara Fontaine ·

    Do you have a recommendation for someone just starting out? Everything I find assumes years of experience.

  7. Daniel Osei ·

    Thank you for including the code. I adapted it for our docs site in about ten minutes.