Skip to content

How to Extract Plain Text from HTML

By Durim Hoti · Last updated

Copying text out of a browser often drags along formatting, and selecting it from the source code means picking around tags. Typical reasons to extract the text are a plain-text version of an HTML email, a word count, text for a translation tool, or content for a document that has no formatting at all.

Extract the text step by step

  1. Open the HTML to text converter.
  2. Paste the HTML, or click Open file (or drop an .html file on the page).
  3. Choose the options: Preserve line breaks, Remove extra whitespace, Keep link text and Include link URLs.
  4. Check the plain text on the right; the counter shows words and characters.
  5. Click Copy text or Download TXT.

Example: a plain-text version of an order email

HTML emails are built from nested tables and inline styles. This shipping notification has a link, a small product table, a hidden preheader and a logo:

order-email.html
<table role="presentation" width="100%">
  <tr><td>
    <h1>Your order has shipped</h1>
    <p>Hi Anna,<br>your order <strong>#4821</strong> is on its way.</p>
    <p><a href="https://example.com/track/4821">Track your package</a></p>
    <table>
      <tr><th>Item</th><th>Qty</th></tr>
      <tr><td>Desk lamp</td><td>1</td></tr>
      <tr><td>LED bulb&nbsp;E27</td><td>2</td></tr>
    </table>
    <p style="display:none">Preheader text hidden in the inbox</p>
    <img src="logo.png" alt="Shop logo">
    <!-- tracking pixel -->
    <style>p { color: #333; }</style>
  </td></tr>
</table>

With the default options plus Include link URLs, the converter returns:

Plain text
Your order has shipped

Hi Anna,
your order #4821 is on its way.

Track your package [https://example.com/track/4821]

Item	Qty
Desk lamp	1
LED bulb E27	2

Preheader text hidden in the inbox

Shop logo
The HTML to text converter with all four options ticked. The order email HTML is on the left; the plain text on the right shows the heading, the greeting on two lines, Track your package followed by the URL in square brackets, the item table and the hidden preheader text. The counter reads 34 words, 201 characters.
The order email as plain text: 34 words, 201 characters.

What happened to each part:

  • The <br> after "Hi Anna," became a line break; paragraphs and the heading are separated by blank lines.
  • The link kept its text, and the address followed in square brackets because Include link URLs was on.
  • The table cells are separated by tab characters. &nbsp; became a normal space.
  • The HTML comment and the <style> block are gone.
  • The preheader is still there, although display:none hides it in the inbox, and the logo was replaced by its alt text "Shop logo".

What the options change

Preserve line breaks keeps the structure. Turned off, the same email becomes one line, which suits a search index or a single spreadsheet cell:

Preserve line breaks off
Your order has shipped Hi Anna, your order #4821 is on its way. Track your package Item Qty Desk lamp 1 LED bulb E27 2 Preheader text hidden in the inbox Shop logo

Keep link text turned off removes links completely, text included; in the example, "Track your package" disappears. Remove extra whitespace collapses the indentation and repeated spaces that come from the HTML source.

Numbered lists get their numbers, and preformatted text in <pre> keeps its spaces:

HTML
<p>Steps:</p><ol><li>Open the file</li><li>Copy the text</li></ol><pre>  x = 1
  y = 2</pre>
Plain text
Steps:

1. Open the file
2. Copy the text

  x = 1
  y = 2

Common problems

Hidden text shows up

The converter doesn't apply CSS, so it can't know what is hidden. Email preheaders, mobile-only menus and cookie notices hidden by a stylesheet appear in the text. Delete those elements from the HTML first, or remove the lines from the result.

Words from images appear

Alt text is the text equivalent of an image, so it is kept. If you don't want it, remove the alt attributes or the lines afterwards.

The text is missing parts of the page

If the page builds its content with JavaScript, the saved source may contain little text. Copy the rendered HTML instead: in Chrome, right-click the page, choose Inspect, right-click the <html> element and copy its outer HTML.

Strange characters such as é instead of é

The file isn't UTF-8. Files are read as UTF-8, so open the file in a text editor, save it as UTF-8 and open it again.

What to do next

To read the HTML itself more easily, see how to format HTML code. Going the other way, from plain text to paragraphs and links, works with the text to HTML converter. Starting from a Word file instead? See how to convert Word to HTML.

FAQ

Is the page title included in the text?
No. Everything in the <head>, including the <title>, is skipped, as are scripts, styles, SVG graphics, iframes and <noscript> blocks. Only the visible body content is converted.
Can I keep the link addresses?
Yes. Tick Include link URLs and each link becomes its text followed by the address in square brackets, for example Track your package [https://example.com/track/4821].
Can I extract text from a web page by its URL?
No. Paste the page's HTML or open a saved .html file. In most browsers you can save a page with Ctrl+S (Cmd+S on a Mac) or copy its source from View page source.
Is my HTML uploaded?
No. The HTML is parsed and converted in your browser. Files up to 10 MB can be opened.
How do I count the words of an HTML page?
Convert it to text: the counter above the plain text shows words and characters of the result, so tags and attributes aren't counted.

Try it and keep reading