What Are HTML Tags?
HTML tags are the markup codes that define the structure and formatting of web content. Tags are enclosed in angle brackets: <h1> defines a heading, <p> defines a paragraph, <a href="..."> defines a link, <strong> defines bold text. When you view a web page, you see the rendered content — the text, images, and layout. The underlying HTML tags are hidden by the browser but present in the source code.
Strip all HTML tags from any content with WritePadPro's Strip HTML Tags tool — paste HTML and get clean plain text with all markup removed instantly.
Stripping HTML tags means removing all the markup codes while preserving the visible text content. The HTML <h1>Hello <strong>World</strong></h1> becomes the plain text "Hello World" — the tags are removed, the text remains.
Why Strip HTML Tags?
There are many practical scenarios where you need plain text extracted from HTML content.
Email Cleanup
HTML emails contain extensive markup — tables for layout, inline styles for formatting, tracking pixels, and embedded images. When you need the text content of an email for analysis, quoting, or plain-text forwarding, stripping the HTML extracts just the readable content. A 50 KB HTML email might contain only 500 words of actual text buried in 45 KB of markup.
CMS Migration
Moving content between content management systems (WordPress to Shopify, Drupal to HubSpot, custom CMS to any platform) often requires extracting plain text from the source system's HTML. Different CMS platforms use different HTML structures, classes, and formatting conventions. Stripping tags produces clean text that can be reformatted in the destination system without carrying over incompatible markup.
Data Extraction and Scraping
Web scraping retrieves HTML pages, but the useful content is the text within the tags, not the tags themselves. Product descriptions, article content, review text, and pricing information must be extracted from their HTML wrappers for analysis, storage, or re-publishing. For encoding the extracted content safely, see the HTML Encoder & Decoder.
SEO Content Analysis
Analyzing the actual text content of a page — word count, readability, keyword density — requires stripping HTML first. Tags like <div> and <span>, attributes like class="...", and inline styles add characters that are not visible content. Accurate text analysis operates on the stripped plain text, not the raw HTML source.
Word Counting Raw Content
If you paste HTML source code into a word counter, every tag is counted as words — <div class="container"> registers as 2 words that are not actual content. Stripping tags first ensures your word count reflects only the visible text. For clean word counting after stripping, see our Remove Extra Spaces Guide — stripping tags often leaves behind extra whitespace.
Accessibility and Plain Text Versions
Some systems require plain text alternatives: email campaigns need both HTML and plain text versions, accessibility compliance may require plain text alternatives for complex HTML, and some API endpoints accept only plain text. Stripping tags produces the plain text version from existing HTML content.
What Gets Removed vs What Stays
Removed (Tags and Attributes)
- All opening tags:
<h1>,<p>,<div>,<span>,<a href="..."> - All closing tags:
</h1>,</p>,</div> - Self-closing tags:
<br />,<img src="..." />,<hr /> - All attributes within tags: class, id, style, href, src, data-*
- Comments:
<!-- comment --> - Script and style blocks:
<script>...</script>,<style>...</style>
Preserved (Text Content)
- All visible text between tags
- Text within links (the anchor text, not the URL)
- Text within formatting tags (bold text, italic text — the words, not the formatting)
- HTML entities (decoded to their character equivalents):
&becomes &,<becomes the less-than sign
Edge Cases
- Alt text: Image alt attributes (
<img alt="description">) are lost when tags are stripped. If you need alt text preserved, read the alt attributes with a DOM-based script; WritePadPro’s tool, like most strippers, leaves them out. - Link URLs: The text "Click here" is preserved, but the URL in
href="https://..."is lost. For content where URLs matter, extract them separately — or, in WritePadPro’s tool, tick Keep link URLs to write each link as “link text (URL)”. - Table data: Table markup is removed, but cell content is preserved. A simple stripper turns a table into a flat text sequence that may be hard to interpret; WritePadPro’s tool, with Keep line breaks on, puts each row on its own line and separates cells with tabs.
For viewing HTML with tags preserved rather than stripped, use the HTML Preview tool. For related cleanup after stripping, see our Remove Punctuation Guide.
Regex vs DOM Parsing: Two Approaches
There are two fundamentally different technical approaches to stripping HTML tags, each with distinct trade-offs.
Regex Approach (Simple but Fragile)
The most common quick method uses a regular expression to match and remove anything between angle brackets:
text.replace(/<[^>]+>/g, "")This pattern matches any sequence starting with < and ending with >, and replaces it with nothing. It is fast, simple, and works for most well-formed HTML.
Limitations:
- Does not handle malformed HTML (tags missing closing brackets)
- Does not remove content inside script and style tags — it removes the tags but leaves the JavaScript/CSS code as visible text
- Does not decode HTML entities (leaves
&as literal text instead of converting to &) - Can be tricked by angle brackets in text content or attributes
DOM Parsing Approach (Robust but Heavier)
The browser's built-in DOM parser understands HTML structure. Use it to extract text content:
// JavaScript
var doc = new DOMParser().parseFromString(htmlString, "text/html");
doc.querySelectorAll("script, style").forEach(function (el) { el.remove(); });
var text = doc.body.textContent;This approach:
- Handles malformed markup the same way a browser does
- Lets you drop script and style elements together with their content (
textContenton its own would keep that code as text) - Automatically decodes HTML entities
- Handles nested tags, self-closing tags, and comments correctly
- Parses into an inert document, so scripts in the pasted HTML do not run and images are not loaded. Assigning untrusted HTML to
innerHTMLof an element on the live page, as many snippets do, can fire handlers such asonerror.
WritePadPro uses the DOM parsing approach for accurate, reliable tag stripping.
Language-Specific Methods
| Language | Method |
|---|---|
| JavaScript | new DOMParser().parseFromString(html, "text/html").body.textContent |
| Python | from bs4 import BeautifulSoup; BeautifulSoup(html, "html.parser").get_text() |
| PHP | strip_tags($html) (simple tag removal) or DOMDocument (DOM-based) |
| Java | Jsoup.parse(html).text() |
| C# | HtmlAgilityPack: doc.DocumentNode.InnerText |
| Ruby | Nokogiri::HTML(html).text |
Security: Stripping Tags for XSS Prevention
Stripping HTML tags is sometimes used as a security measure to prevent Cross-Site Scripting (XSS) attacks — but it is NOT a reliable security method by itself.
Why Tag Stripping Alone Is Insufficient
- Attribute-based attacks:
<img src=x onerror=alert(1)>— the tag is an image tag, but theonerrorattribute executes JavaScript. Simple tag stripping that allows<img>tags leaves this attack vector open. - URL-based attacks:
<a href="javascript:alert(1)">Click</a>— the tag is a link, but the href contains executable JavaScript. - CSS-based attacks:
<div style="background:url(javascript:alert(1))">— older browsers executed JavaScript in CSS URLs. - Incomplete stripping: Nested or malformed tags can bypass regex-based strippers.
The Correct Security Approach
For XSS prevention, use HTML entity encoding (converting dangerous characters to their entity equivalents) rather than tag stripping. Encoding < to < and > to > makes all HTML harmless without removing any content. Most modern web frameworks and template engines encode output automatically. For encoding details, see our HTML Entities Guide.
Tag stripping is appropriate for content extraction (getting plain text from HTML). It is NOT appropriate as a sole security measure against XSS. For detecting hidden characters that might bypass security filters, see our Invisible Characters Guide.
Post-Stripping Cleanup
After stripping HTML tags, the resulting text typically needs additional cleanup.
Extra Whitespace
With simple strippers, HTML tags that occupied their own lines leave behind blank lines, and source indentation turns into stray spaces. WritePadPro’s tool collapses source whitespace the way a browser does and keeps at most one blank line between blocks, so its output is usually tidy already. If you still need to, run the text through Remove Extra Spaces or Remove Empty Lines.
Residual Entities
If using regex-based stripping (not DOM parsing), HTML entities like , &, — remain as literal text instead of being decoded. DOM-based stripping (which WritePadPro uses) decodes these automatically.
Orphaned Formatting
Content that relied on HTML structure for meaning — tables, lists, multi-column layouts — loses its structural context when tags are stripped. A simple stripper turns a table into a flat sequence of cell values (WritePadPro keeps one row per line, with tab-separated cells), and a two-column layout can become interleaved content. Review stripped content for structural elements that need manual reorganization.
Using WritePadPro's Strip HTML Tags Tool
WritePadPro's Strip HTML Tags tool extracts clean plain text from any HTML content.
Step 1: Paste Your HTML
Open the Strip HTML Tags tool and paste your HTML source code — from web pages, email source, CMS exports, or any HTML content.
Step 2: Choose Options and Strip Tags
Two options shape the output. Keep line breaks (on by default) turns paragraphs, headings, list items, table rows and <br> tags into new lines; untick it to join everything into one line. Keep link URLs writes each link as “link text (URL)”. Click Strip Tags. The tool parses the HTML with the browser’s DOM parser, drops script, style, noscript, template, iframe, object and embed elements with their content, decodes entities, and extracts only the visible body text. The plain text appears in a separate output box, and your original HTML stays untouched.
Step 3: Review the Results
The tool shows statistics:
- HTML tags removed — how many tags were stripped
- Script/style blocks removed — non-visible elements dropped with their content
- Characters before → after — the size of the HTML compared with the plain text
- Words in output and Lines in output
Step 4: Clean Up and Use
Copy the plain text or download it as a .txt file. The extracted text is ready for word counting, readability analysis, content migration, or any plain text use case.
Privacy
All processing runs locally in your browser using the DOM parser. Your HTML content — including email source code, proprietary templates, and scraped data — is never transmitted to any server.
Summary
Stripping HTML tags extracts the visible text content from HTML markup, removing all tags, attributes, comments, and script/style blocks. The two main approaches are regex-based (simple but fragile) and DOM parsing (robust and accurate). WritePadPro uses DOM parsing for reliable results.
Common use cases include email cleanup, CMS migration, data extraction, SEO content analysis, and creating plain text versions of HTML content. Remember: tag stripping is for content extraction, not security. For XSS prevention, use HTML entity encoding instead.
Extract plain text from HTML with WritePadPro's Strip HTML Tags tool — DOM-based parsing in your browser with complete privacy. Follow up with the Remove Extra Spaces Guide for post-stripping whitespace cleanup.