Parse HTML to Text: What Extraction Keeps, Drops and Changes
A practical review of parsing HTML to plain text from a web page: what the conversion removes, what it preserves, and when the result is usable for reading, search, editing or sharing.
Turning a web page's HTML into plain text sounds simple: remove the tags and keep the words. In practice, the result depends on how the extractor treats structure, hidden elements, scripts, styling and content that only appears after the page runs JavaScript. This review explains what the conversion changes, where it works well, and where it quietly loses meaning. No specific extraction tool was tested for this article, so it describes documented web-standard behavior and general principles rather than measured results.
Is HTML-to-text extraction suitable for your use?
Plain-text extraction is a good fit when you need the words of a page and not its layout. Typical examples include quoting or summarizing an article, feeding text into search indexing or analysis, comparing versions of a page, or moving content into an editor that would otherwise inherit unwanted formatting. Here, plain text is often the better form because it is small, easy to edit and free of markup.
The decisive tradeoff is structure. Headings, emphasis, tables, link destinations and the relationships between elements are expressed in markup, and extraction removes most or all of that markup. If you need those relationships, such as a table's rows and columns or the address behind each link, plain text alone is not enough. Keep the HTML, or convert to a lightweight structured format like Markdown, instead.
- Plain text is usually the right choice for: reading the article body, quoting, keyword or text analysis, diffing content changes, and pasting into editors without carrying styles over.
- Plain text is a weak choice for: data tables, pages whose meaning depends on layout, content where link targets matter, and material that must keep heading levels or other semantics for accessibility.
- Plain text may be incomplete for: pages that build their content with JavaScript, unless the extractor renders the page before reading it.
What the conversion actually changes
Parsing HTML to text does not reverse, mirror or substitute characters. It reads the document's structure and outputs the text nodes, usually with some formatting decisions applied. Most changes fall into three groups: markup that is removed, characters that are decoded, and presentation that may or may not be honored.
| Element of the page | Typical result in plain text | Why it matters |
| Tags such as headings, paragraphs and lists | Removed; block elements usually become line breaks | Hierarchy is lost unless the tool adds markers |
| Character entities such as & or | Decoded to the actual characters | Output should read as normal text; a non-breaking space may remain a distinct character |
| Link anchor text | Usually kept | The visible words survive |
| Link destination | Usually dropped unless the tool is set to include it | References and citations can lose their target |
| Image alt text | Varies by tool | Captions or descriptions may vanish |
| Script and style contents | Should be excluded; naive methods may include them | Code fragments can pollute the output |
| Tables | Flattened into lines or runs of text | Row and column relationships are often lost |
| CSS-hidden content | Depends on whether the tool applies CSS | Hidden menus or duplicate text may appear |
The last row reflects an important distinction between stored content and visual presentation. In browsers, the DOM's textContent property returns every text node in the source, including text inside script and style elements and text hidden with CSS, and it follows the source's whitespace rather than adding line breaks for block elements. The innerText property, by contrast, is defined in the HTML standard to take CSS rendering into account: it omits content that is not rendered, inserts line breaks for block-level boxes, and applies CSS text-transform. An extractor that works on raw HTML without a rendering engine behaves more like textContent than innerText.
An illustrative example of a block-aware extraction is shown below. It shows the expected mechanism, not the output of any particular tool: tags are removed, the entity is decoded, block elements and the line break become new lines, the inline strong element joins its surrounding text, and the script is excluded.
<h1>Fish & Chips</h1>
<p>Open <strong>daily</strong>.<br>Call ahead.</p>
<ul><li>Cod</li><li>Haddock</li></ul>
<script>track()</script>
--- block-aware plain text ---
Fish & Chips
Open daily.
Call ahead.
Cod
Haddock
Tools differ on details. Some add bullet characters to list items or blank lines between paragraphs. Some write heading text in capitals or mark it with symbols. A naive approach that simply strips tags may produce "track()" in the output, and if the source has no whitespace between elements, it may run words together, as in "CodHaddock".
Fonts, stylized characters and text direction
The word "font" means two different things on a web page. A CSS font, along with bold, italic, color and size set through stylesheets, is presentation; it does not survive extraction to plain text. Stylized Unicode characters, such as mathematical bold or script letters used as "fancy fonts", are different code points stored in the text itself. Extraction keeps them unchanged, along with their usual drawbacks for search and screen readers. Similarly, capital letters produced by CSS text-transform are not in the source, so a raw-HTML extractor outputs the original case, while a rendering-aware method like innerText outputs the transformed case.
For right-to-left scripts, HTML stores text in logical order, the order in which it is read, and the browser's bidirectional algorithm arranges it visually. Extracted text stays in logical order, which is correct for storage and processing. When it is pasted into an environment without bidi support or with a different base direction, mixed left-to-right and right-to-left runs, especially those involving numbers or punctuation, may display in a confusing order. Direction set through the dir attribute or CSS is lost in plain text, unless explicit Unicode directional control characters are present in the content.
Fetching a page from its web address
When you give an extractor a web address instead of pasted HTML, it first has to retrieve the page. Three limits follow from how the web works. First, many pages load their main content with JavaScript after the initial HTML arrives, so a tool that only downloads the HTML may return navigation and boilerplate but miss the article. Only a tool that renders the page in a browser engine can see that content. Second, pages that require a login, show a consent screen or block automated requests may return something other than what you see in your own browser. Third, extracting the whole page usually includes menus, footers and cookie notices, unless the tool attempts to isolate the main content. Such main-content detection is heuristic and can cut off or include the wrong sections.
Submitting a web address or pasted HTML to an online service sends that content to the service. Its handling and retention of the data can only be learned from the service's own stated policies, not from its appearance or descriptions. For private or sensitive pages, running a parser locally avoids this question.
Will the text stay readable and usable after copying or sharing?
Plain text is the most portable form of content: it pastes into almost any editor, message field or form without carrying over styles. Problems mostly come from what was lost during extraction rather than from the pasting itself.
- Reading order: extraction follows the order of the HTML source. CSS layout features such as flexbox or grid reordering and absolute positioning can make the visual order differ from the source order, so sidebars, captions or pull quotes may appear in unexpected places in the text.
- Accessibility: screen readers rely on semantic markup such as heading levels, lists, table headers and link roles to navigate. Once converted to plain text and republished, that navigation structure is gone. If the text will be shared as accessible content, restore the structure in the destination format rather than relying on line breaks.
- Search: extracted text is well suited to full-text search and analysis because it removes markup noise. However, it loses signals such as which words were headings or link text, and CSS-hidden or boilerplate text can mix in with the main content.
- Editing: plain text is easy to edit. Expect to clean up extra blank lines, leftover non-breaking spaces, and lines that merged or split at element boundaries.
- Links and references: if link destinations matter to the meaning, such as in citations, sources or calls to action, choose an option that includes the address next to the anchor text, or keep the HTML.
A plain-text version is needed when the destination accepts only plain text, when you want to remove tracking or styling markup, or when the content will be processed by software rather than read by people. Keep a structured version alongside it when the text must remain navigable for assistive technology or when tables and link targets carry essential information.
Gaps in this review
No specific extractor, website or destination application was tested for this article, and no supplied evidence covered named tools, accuracy rates or performance. The behavior described here comes from web standards and general parsing principles. Behavior with a particular screen reader, word processor, messaging app or search system has not been verified and may vary. Before relying on a tool, test it on a few representative pages from your actual sources, including one that depends on JavaScript and one with tables or right-to-left text, and check the output in the place where you plan to use it.