Skip to content
gohacks.dev
Web

Strip HTML Tags

Remove HTML tags from markup and keep the text, with entities decoded, scripts and styles removed and paragraph breaks preserved.

Free · No sign-up · Your inputs stay in your browser

Input

Strip HTML tags and keep the text

Output

Plain text

0 characters

Entities are decoded (& becomes &) and script and style contents are removed rather than kept as text, which is the usual bug in a regex-based strip_tags. The HTML is parsed into an inert document, so nothing in it runs.

Runs in this browser. Nothing you paste is sent to a server.

Why a regex is not enough

Replacing <[^>]+> with nothing leaves the contents of script and style tags in the text, glues words together where block elements met, and leaves entities encoded. PHP's strip_tags() has the same problems with scripts. Parsing the HTML first, as browsers do, avoids all three.

Stripping is not sanitising

Plain text from this tool is safe to display because it contains no markup. If you need to keep some formatting from untrusted HTML, use a sanitiser with an allow-list instead, such as DOMPurify in the browser or HTML Purifier and Symfony's HtmlSanitizer in PHP; removing tags you can think of is how XSS filters get bypassed.

Share

Frequently asked questions

How do I strip HTML tags in PHP?
strip_tags($html) removes tags but keeps the text inside script and style elements. For clean text, parse with DOMDocument, remove those elements, and read textContent.
Are HTML entities converted?
Yes. &amp;amp;, &amp;nbsp; and numeric references are decoded into the characters they stand for.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools