Stripping HTML Tags: Turning Web Pages Into Clean Plain Text
Copying text from a web page often brings the markup with it: tags, attributes, scripts and styles that were never meant to be read. Stripping HTML turns that markup back into plain text, which is what you need for a word count, a search index, a plain-text email, or a dataset of article text. The Remove HTML Tags tool does this in your browser, and the quality of the result depends on understanding what stripping actually does to the text, because the naive version has a well-known flaw.
The naive approach is to delete everything between < and >. That removes the tags, but it also removes the boundaries the tags represented. Consider <p>Hello</p><p>World</p>: deleting the tags gives "HelloWorld", with the two paragraphs glued into one word. The fix is to replace block-level boundaries with a space or a line break before removing the tags, so paragraphs, headings and list items stay separated. A good stripper treats block elements as separators and inline elements, such as bold or link tags, as invisible, which preserves both the words and the structure. The distinction between block and inline is the single most important detail in HTML stripping, and it is what separates a usable result from a wall of glued words.
Scripts, styles and comments need different handling again. The content inside <script> and <style> tags is code, not text, and it must be removed entirely, not stripped of its tags and left behind. A naive stripper that deletes only the tags would leave JavaScript source code in the middle of your article text. HTML comments, which are invisible in a browser, should also be removed rather than exposed. Head content, such as the title and meta tags, is usually not part of the article text either, and a stripper aimed at article extraction removes it. Knowing what your stripper removes, beyond the tags themselves, is essential before you trust its output for a word count or a dataset.
Entities are the next layer. HTML represents special characters as entities: & for an ampersand, < for a less-than sign, for a non-breaking space, and numeric forms such as © for the copyright sign. A good stripper decodes these back to their characters, so Tom & Jerry becomes "Tom & Jerry". A stripper that skips decoding leaves the entity codes in the text, which corrupts word counts and looks wrong to any human reader. Non-breaking spaces deserve a warning: they look like ordinary spaces but are a different character, and they can break exact-match searches and strict comparisons downstream, so converting them to regular spaces is usually the right choice.
A worked example you can follow
Take this short HTML fragment:
<h1>Fruit Guide</h1>
<p>Apples & pears are <strong>popular</strong>.</p>
<p>They grow on trees.</p>
Count the tags: h1 open and close (2), p open and close twice (4), strong open and close (2), for 8 tags in total. A naive strip that deletes all 8 tags and nothing else gives "Fruit GuideApples & pears are popular.They grow on trees.", with three defects: the heading glued to the first paragraph, the entity left undecoded, and the full stop glued to the next sentence. A proper strip that replaces block boundaries with line breaks and decodes entities gives:
Fruit Guide
Apples & pears are popular.
They grow on trees.
That is 3 lines and 10 words in total (Fruit, Guide, Apples, pears, are, popular, They, grow, on, trees), and the count check is what catches a glued pair: if your count shows 9, two words were glued together somewhere. The arithmetic of the check matters: count the words in the original rendered page, count them in the stripped output, and the two counts must match. A mismatch means something was glued, dropped or left behind, and the location of the mismatch points at the defect.
Verify the output before using it for anything strict. Search for leftover angle brackets, which indicate a malformed tag the stripper missed, and search for entity codes such as & or &#, which indicate decoding failed. Read the first and last lines, where boundary gluing is most common, and confirm that scripts and styles did not leak through as code. For a long document, spot-check a paragraph from the beginning, middle and end rather than reading the whole output.
Common mistakes to avoid
The most common mistake is using naive tag deletion and getting glued words throughout the text. A second mistake is leaving script and style content in the output, which pollutes word counts and datasets with code. A third mistake is forgetting entity decoding, so the text is full of & codes. A fourth mistake is stripping the only copy of a document whose markup carried meaning, such as links or emphasis that a later step needed; strip a copy, not the original. A fifth mistake is assuming stripped text is clean enough for a strict parser without checking for non-breaking spaces and leftover brackets.
Stripped text is a raw material, not a finished product. It needs a read-through, a word-count check, and often a second cleanup pass for empty lines and spacing before it is ready for its destination. Done in that order, stripping turns a web page into text you can actually use.
Frequently asked questions
Why are words glued together after stripping? Because block boundaries were deleted instead of replaced with a space or a line break; a stripper that treats blocks as separators fixes this.
What happens to links? The link text survives and the URL is dropped, unless the stripper has an option to keep URLs, so save any links you need before stripping.
Can stripping break text? It can drop structure, emphasis and links, and it can expose hidden content if scripts and comments are not removed, so strip a copy and verify the result.
For related text preparation, see HTML Formatter Guide, and pair this tool with the Remove Empty Lines and the Word Counter when turning a page into clean text. Strip the tags, keep the boundaries, and count the words.