> ## Documentation Index
> Fetch the complete documentation index at: https://docs.marblecms.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Reading Time

> Calculate and display estimated reading time for Marble posts with a small TypeScript helper that strips HTML and counts words per minute.

Some blogs like to show an estimated reading time for each post. Marble provides these estimates inside the editor interface, but you can also display them on the frontend of your site.

## How It Works

The math behind reading time is fairly simple: it's based on an average reading speed of 238 words per minute (often rounded to 200 for simplicity).

## Implementation

This is a simple function you can use to calculate reading time for any given content:

```ts theme={"theme":{"light":"github-light","dark":"github-dark"}}
export function calculateReadTime(content: string): number {
  const wordsPerMinute = 238;
  const plainText = content.replace(/<[^>]*>/g, "").trim();
  const wordCount = plainText.split(/\s+/).length;

  const readingTime = Math.ceil(wordCount / wordsPerMinute);
  return readingTime;
}
```

To then use this function, simply pass in the HTML content of your post, and it will return the estimated reading time in minutes.

```tsx theme={"theme":{"light":"github-light","dark":"github-dark"}}
const readTime = calculateReadTime("<p>Your post content goes here...</p>");
```

You can then use that number to display the reading time on your post pages. Feel free to tweak the words-per-minute value to better suit your audience!
