Strip HTML Tags: how it works and how to build one
Remove HTML tags and get plain, readable text. This guide explains what happens behind the button and shows the code, so you can build your own.
What it does
Removes every tag, script and style, decodes entities like & and keeps paragraph breaks if you want them. Good for cleaning copied web content, email templates and CMS exports.
When to use it
- Cleaning text copied from web pages
- Plain-text versions of emails
- Word counts of HTML content
How to use it
- Paste HTML.
- Choose whether to keep line breaks.
- Copy the plain text.
Try it free in your browser, nothing is uploaded: https://eskillsfy.com/tools/strip-html
How it works
Stripping HTML means removing every tag but keeping the text. Scripts and styles are removed with their content first. To keep the structure, closing </p>, </div> and <br> tags become new lines before all tags are removed.
Finally, entities like & and are decoded and extra spaces collapsed.
Build it yourself
Here is the core of the tool. It has no dependencies unless noted, so you can paste it into any TypeScript or JavaScript project.
stripHtml.ts (ts)
export function stripHtml(html: string) {
// In the browser, DOMParser does the hard part safely (scripts never run):
const doc = new DOMParser().parseFromString(html, "text/html");
doc.querySelectorAll("script, style").forEach((n) => n.remove());
doc.querySelectorAll("br").forEach((n) => n.replaceWith("\n"));
doc.querySelectorAll("p, div, li, h1, h2, h3, tr").forEach((n) => n.append("\n"));
return (doc.body.textContent ?? "").replace(/[ \t]+/g, " ").replace(/\n\s*\n+/g, "\n\n").trim();
}
Make it production-ready
- Keep link URLs in brackets after the link text.
- Offer a regex version that works on the server.
Questions
Are links kept?
Only the link text is kept. Use HTML to Markdown if you need the URLs too.
Free, runs in your browser, nothing is uploaded.