Awesome Open Source
Awesome Open Source


Documentation Build Status Report Card

Converts HTML into text of the markdown-flavored variety


Ensure your emails are readable by all!

Turns HTML into raw text, useful for sending fancy HTML emails with an equivalently nicely formatted TXT document as a fallback (e.g. for people who don't allow HTML emails or have other display issues).

html2text is a simple golang package for rendering HTML into plaintext.

There are still lots of improvements to be had, but FWIW this has worked fine for my [basic] HTML-2-text needs.

It requires go 1.x or newer ;)

Download the package

go get

Example usage

package main

import (


func main() {
	inputHTML := `
    <title>My Mega Service</title>
    <link rel=\"stylesheet\" href=\"main.css\">
    <style type=\"text/css\">body { color: #fff; }</style>

    <div class="logo">
      <a href=""><img src="/logo-image.jpg" alt="Mega Service"/></a>

    <h1>Welcome to your new account on my service!</h1>

      Here is some more information:

        <li>Link 1: <a href=""></a></li>
        <li>Link 2: <a href=""></a></li>
        <li>Something else</li>

        <tr><th>Header 1</th><th>Header 2</th></tr>
        <tr><td>Footer 1</td><td>Footer 2</td></tr>
        <tr><td>Row 1 Col 1</td><td>Row 1 Col 2</td></tr>
        <tr><td>Row 2 Col 1</td><td>Row 2 Col 2</td></tr>

	text, err := html2text.FromString(inputHTML, html2text.Options{PrettyTables: true})
	if err != nil {


Mega Service ( )

Welcome to your new account on my service!

Here is some more information:

* Link 1: ( )
* Link 2: ( )
* Something else

|  HEADER 1   |  HEADER 2   |
| Row 1 Col 1 | Row 1 Col 2 |
| Row 2 Col 1 | Row 2 Col 2 |
|  FOOTER 1   |  FOOTER 2   |


Running the unit-tests is straightforward and standard:

go test


Permissive MIT license.


You are more than welcome to open issues and send pull requests if you find a bug or want a new feature.

If you appreciate this library please feel free to drop me a line and tell me! It's always nice to hear from people who have benefitted from my work.

Email: jay at (my github username).com

Twitter: @jtaylor

Alternatives - Lightweight

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
go (15,340
golang (3,955
plaintext (17
html-emails (16