Xerobit

Text File to HTML Converter: Plain Text to Markup

Paste the contents of a text file and get valid HTML back: blank lines become paragraphs, single line breaks become br tags, URLs and email addresses become links, and special characters are escaped. It runs in your browser.

Adds doctype, head, charset and title.

Result

<p>Release notes<br>
Version 2.4 is out.</p>
<p>Read the changelog at <a href="https://example.com/changes?v=2&amp;lang=en">https://example.com/changes?v=2&amp;lang=en</a> or write to <a href="mailto:support@example.com">support@example.com</a>.</p>
<p>Costs &lt; $5 &amp; ships &quot;today&quot;.</p>

3 paragraphs, 2 links.

How to use the text to html converter

  1. Open your .txt file in any editor, select everything and paste it into the Plain text box.
  2. Choose a structure: paragraphs, one paragraph per line, line breaks only, or preformatted text.
  3. Leave link detection on if you want URLs and email addresses to become clickable, and tick the full page option if you need a standalone file.
  4. Copy the HTML from the result box and paste it into your page, CMS or email template.

Change text to HTML: what the converter does

To change text to html you have to do three jobs: mark where blocks of text start and end, make sure characters like < and & do not get read as markup, and optionally turn web addresses into links. This converter does all three in one pass, so a text file to html conversion that used to need a search and replace script takes one paste.

Nothing is guessed about fonts or colours. A plain text file carries no formatting, so the output is clean semantic markup that picks up the styles of whatever page you put it in.

Converting text to HTML: paragraphs, line breaks and pre

Converting text to html starts with the structure choice, because browsers collapse whitespace and ignore newlines in normal text. The four modes handle that in different ways.

ModeBlank lineSingle line breakBest for
ParagraphsEnds a <p><br> inside the paragraphArticles, emails, notes
One paragraph per lineIgnoredStarts a new <p>Lists of statements
Line breaks onlyExtra <br><br>Poems, addresses, signatures
PreformattedKeptKeptLogs, code, aligned columns

Leading and trailing spaces on each line are trimmed in the first three modes, because HTML would collapse them anyway. Preformatted mode keeps every space and newline exactly.

Convert a text file to HTML safely

To convert text file to html without breaking the page, every special character is escaped: & becomes &amp;, < becomes &lt;, > becomes &gt; and double quotes become &quot;. A line such as if (a < b && c) therefore shows up as text instead of opening a tag, and a pasted <script> is displayed rather than run.

If your target system is not UTF-8, switch non-ASCII characters to numeric entities: the letter e with an acute accent becomes &#233; and the euro sign becomes &#8364;. For escaping rules in more detail, see the HTML escape tool.

Rich text to HTML: what this tool does not do

This tool starts from plain text. If you copy from Word or Google Docs, the browser flattens bold, italics, headings and lists to bare text when you paste into the box, so those styles are lost. Rich text to html conversion needs a source that still carries the formatting.

Two routes keep it: write the document in Markdown and use the Markdown to HTML converter, or paste into a rich editor and read its source view. To go the other way, the HTML to text tool strips markup back out.

Common problems and how to avoid them

Text that looks fine in the editor but runs together in the browser nearly always lacks block structure: use the paragraph mode for prose. Columns of aligned numbers collapse into single spaces unless you choose preformatted.

  • Smart quotes and dashes from a word processor are kept as typed. They are fine in UTF-8 pages.
  • Tabs are not converted into table cells. Use the text to table converter for tabular data.
  • Very long unbroken strings, such as base64 blobs, will not wrap on narrow screens unless you add a CSS rule like overflow-wrap: anywhere.

Worked examples

ExampleInputResult
Notes with a linkPlain text: Hello team, / the draft is at www.example.com/draft. / Thanks!; Structure: paragraphs; Link URLs and email addresses: yes; Non-ASCII characters: keep; Wrap in a full HTML page: no; Page title: Notes<p>Hello team,<br> / the draft is at <a href="https://www.example.com/draft">www.example.com/draft</a>.</p> / <p>Thanks!</p>
One paragraph per linePlain text: First point / Second point / Third point; Structure: lines; Link URLs and email addresses: yes; Non-ASCII characters: keep; Wrap in a full HTML page: no; Page title: List<p>First point</p> / <p>Second point</p> / <p>Third point</p>
Poem with line breaksPlain text: Roses are red, / Violets are blue. / A < B & C; Structure: br; Link URLs and email addresses: no; Non-ASCII characters: keep; Wrap in a full HTML page: no; Page title: PoemRoses are red,<br> / Violets are blue.<br> / <br> / A &lt; B &amp; C
Full page, ASCII-safePlain text: Café menu / Crème brûlée 6€; Structure: paragraphs; Link URLs and email addresses: yes; Non-ASCII characters: numeric; Wrap in a full HTML page: yes; Page title: Menu<!DOCTYPE html> / <html lang="en"> / <head> / <meta charset="utf-8"> / <meta name="viewport" content="width=device-width, initial-scale=1"> / <title>Menu</title> / </head> / <body> / <p>Caf&#233; menu</p> / <p>Cr&#232;me br&#251;l&#233;e 6&#8364;</p> / </body> / </html>

FAQ

How do I convert a text file to HTML?

Open the .txt file, copy its contents, paste them into the box and copy the generated HTML. Choose the full page option if you want a complete .html document to save.

Does it keep line breaks and blank lines?

Yes. In paragraph mode a blank line starts a new paragraph and a single line break becomes a br tag. Preformatted mode keeps every space and newline exactly.

Can it turn rich text into HTML?

Not from the clipboard: pasting into a text box removes bold, italics and headings. Write Markdown and use the Markdown to HTML converter, or copy the source view of a rich editor.

Are special characters escaped?

Yes. Ampersands, angle brackets and double quotes are converted to entities, so pasted code or markup is shown as text and cannot inject elements into your page.

Which links are detected?

Addresses beginning with http://, https:// or www., and plain email addresses. Punctuation at the end of a sentence stays outside the link.

Is my text uploaded?

No. The conversion runs in your browser, so the text file contents stay on your device.

Sources and references