๐Ÿ”จ All in one Utilities

HTML Tag Stripper

Great utilities that help you design, program and maintain your website

utilities for you to make a website
Home » Utilities » HTML Tag Stripper

HTML Tag Stripper

Everything else is unwrapped, and every attribute is removed except href on links.
Removed
Words
Characters

Note: This is a cleanup tool, not a security boundary. Anything accepted from an untrusted source and shown to other people has to be sanitised on the server โ€” client-side stripping is bypassed by simply not using your client.

Stripping HTML with a regular expression is the classic wrong answer. The pattern everyone reaches for matches anything between angle brackets, which breaks the moment an attribute contains one โ€” a title attribute with a comparison in it, an inline script, a comment containing markup. It also silently turns entity-encoded text into something else, and it happily deletes the contents of a script tag while leaving the code inside it as visible text.

This parses the markup into a document instead and reads the text out of it, which is what the browser itself would do. That means entities are resolved correctly, script and style contents disappear entirely rather than becoming stray text, and an attribute containing a bracket is just an attribute.

The structural options are the ones that decide whether the output is readable. Block-level elements need to become line breaks or every paragraph runs together into a wall; list items need markers or a list becomes a run-on sentence. Converting links to their text plus the URL in brackets is what you want when the destination matters, and dropping them entirely is what you want when it does not.

The allowlist mode is the other half. Rather than removing everything, it keeps a named set of tags and strips the rest along with every attribute โ€” which is the shape you need when accepting formatted text from a user, or cleaning markup pasted out of Word, where the visible text is fine and the sixty spans wrapped around it are not.

This is a cleanup tool, not a security boundary โ€” sanitising untrusted HTML for display belongs on the server.

Frequently Asked Questions

Why not use a regular expression?

Because HTML is not a regular language. The usual pattern breaks on an attribute containing an angle bracket, mishandles comments, mangles entities, and leaves the contents of a script tag as visible text. Parsing gives the same answer the browser would.

Is this safe for sanitising user input?

No. It is a cleanup tool that runs in your browser. Anything accepted from an untrusted source and later displayed to other people must be sanitised server-side with a maintained library โ€” client-side stripping can always be bypassed by not using your client.

Why is my text all on one line?

Because HTML's line breaks are visual, produced by block elements rather than by newlines in the source. Turn on the option that converts block-level elements to line breaks and paragraphs, headings and list items will separate properly.

Can I keep some tags and remove the rest?

Yes โ€” that is the allowlist mode. Name the tags to keep and everything else is unwrapped, with all attributes stripped from what remains. It is the practical way to clean markup pasted from Word, where the text is fine and the wrapper spans are not.

Related Utilities