Text to HTML Converter: Plain Text to Clean HTML
November 11, 2026 · 10 min read
Text to HTML Converter: Turn Plain Text into Clean HTML
A text to HTML converter turns plain text into markup a browser can display. It wraps each paragraph in a <p> tag, turns the line breaks you keep into <br>, escapes characters like & and <, and makes bare URLs into links. Below you'll find each rule with real input and output, a short script, and a Markdown shortcut for headings.
What Does a Text to HTML Converter Do to Your Text?
Plain text has no markup, so a browser shows it as one long run of words. A converter adds the minimum structure needed to keep what you meant. Most converters apply some version of these four rules:
- A blank line starts a new paragraph, so each block gets wrapped in
<p>and</p>. - A single newline inside a block becomes
<br>, or gets ignored, depending on the tool. - The characters
&,<and>become&,<and>so they show up as text. - Anything that looks like a web address becomes an
<a href>link.
Here's a short note before conversion:
Hi team,
The AT&T call moves to 3 pm.
Check if x < 10 before the release.
Slides: https://example.com/q3
And here's what a converter that follows all four rules gives back:
<p>Hi team,</p>
<p>The AT&T call moves to 3 pm.<br>
Check if x < 10 before the release.</p>
<p>Slides: <a href="https://example.com/q3">https://example.com/q3</a></p>
That's an HTML fragment, ready to paste into a page or a CMS field. Some tools also wrap it in a full document with a doctype, a <head> and a <body>. You only need that wrapper when the output is a standalone .html file.
How Do You Convert Plain Text to HTML by Hand?
For a few paragraphs, you don't need a tool at all. Work through the text in this order:
- Replace every
&with&, then every<with<and every>with>. - Wrap each block of text in
<p>and</p>. - Add
<br>only where a line break carries meaning. - Turn each URL into
<a href="...">...</a>.
If the result is going into its own file, put it inside a minimal document. The <meta charset="utf-8"> line tells the browser how to read accented letters, curly quotes and emoji:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Team note</title>
</head>
<body>
<p>Hi team,</p>
<p>The AT&T call moves to 3 pm.</p>
</body>
</html>
Open that file in any browser and you'll see two short paragraphs, with the ampersand displayed as a normal &.
Blank Lines vs Single Newlines: Choosing p or br
HTML treats a newline in your source like a space. Paste a raw .txt file between <body> tags and every line runs together into one block of text. That's why the blank-line rule matters so much: it's the only paragraph signal plain text has.
Use a new <p> for a new thought. Keep <br> for breaks that belong to the content itself. MDN's page on the br element names a poem or a postal address as the right use, and warns against using <br> to add space between paragraphs.
A good converter lets you choose what a single newline does. Email text hard-wrapped at 72 characters wants its newlines ignored. A shipping address wants every one of them kept. Markdown has its own rules for this, covered in our guide to Markdown line breaks. Text copied from a PDF is hard-wrapped too, and our PDF to text guide shows how to rejoin the lines.
Sometimes you want every space kept too, as in a log excerpt, an indented poem or a plain-text table. Skip the paragraph work and wrap the whole escaped block in a <pre> element instead. The browser then shows the text exactly as typed, usually in a monospace font:
<pre>Item Qty
Apples 3
Pears <5</pre>
That renders as a three-line table with its columns lined up. You still have to escape & and < inside <pre>, because the browser parses tags there too.
Which Characters Does a Text to HTML Converter Escape?
Two characters do the real damage in body text. An unescaped < starts a tag, so x <b swallows the rest of your sentence. An & followed by letters can be read as a character reference, so © may turn into a copyright sign.
A converter swaps three characters in body text:
&becomes&<becomes<>becomes>, which rarely breaks anything alone but is escaped by convention
Quotes only matter inside attribute values, such as a link's href, where " and ' stop them ending the value early. Escaping them in body text is harmless, so some tools do it anyway. Our guide to HTML escape characters covers all five codes and the attribute rules.
Order matters. Replace & first, or you'll turn your own < into &lt; and see the code on screen.
Escaping is also a security rule. If your text contains a <script> tag and you write it into a page's HTML unescaped, the browser can run it. The OWASP Cross Site Scripting Prevention Cheat Sheet calls this output encoding and recommends it whenever you need to display text exactly as someone typed it.
A Short Python Script That Converts Text to HTML
You don't have to paste private text into a website. Python's standard library has html.escape, which converts &, < and >. By default it also converts both quote characters. Save this as text_to_html.py:
import html, re, sys
URL = re.compile(r'(https?://[^\s<]+[^\s<.,;:!?)])')
def text_to_html(text):
paragraphs = re.split(r'\n\s*\n', text.strip())
out = []
for para in paragraphs:
safe = html.escape(para) # 1. escape first
safe = URL.sub(r'<a href="\1">\1</a>', safe) # 2. link bare URLs
safe = safe.replace('\n', '<br>\n') # 3. keep single line breaks
out.append(f'<p>{safe}</p>') # 4. wrap each paragraph
return '\n'.join(out)
print(text_to_html(sys.stdin.read()))
Run it on a file called notes.txt:
python3 text_to_html.py < notes.txt > notes.html
With this input:
Hi team,
The AT&T call moves to 3 pm.
Agenda: check if x < 10 and fix the <b> tag bug.
Slides: https://example.com/q3?a=1&b=2.
We ran it, and notes.html contained this:
<p>Hi team,</p>
<p>The AT&T call moves to 3 pm.<br>
Agenda: check if x < 10 and fix the <b> tag bug.</p>
<p>Slides: <a href="https://example.com/q3?a=1&b=2">https://example.com/q3?a=1&b=2</a>.</p>
The literal <b> stays visible as text, and the trailing full stop stays outside the link. The & inside the href is correct, because browsers decode it back to & when they follow the link.
We prefer escaping first and adding tags second. Do it the other way round and the escape step mangles the <p> and <a> tags you just added. In browser JavaScript, you get the same protection by setting an element's textContent instead of its innerHTML, because the browser then treats the whole string as text.
The script has limits. The URL pattern is deliberately simple, so it skips www. addresses and emails. It also produces no headings or lists, because plain text never says where they are. The output is a fragment, so paste it inside the <body> of the skeleton from earlier if you need a standalone page.
What Happens When Plain Text Goes Through Markdown?
Many people skip the script and paste plain text into a Markdown tool, because it handles paragraphs and links for free. That's a fast shortcut, but it isn't neutral. Markdown reads certain characters as instructions:
5*3*2loses its asterisks, and the3turns italic.- A line like
2026. What a year.after a blank line becomes a numbered list that starts at 2026. - A line starting with
#and a space becomes a heading, and a line starting with-and a space becomes a bullet. - After a blank line, a line indented four spaces becomes a code block.
- A bare URL becomes a link, because GitHub Flavored Markdown autolinks
https://andwww.addresses. That one usually helps.
AT&T and a stray x < y come out escaped, which is what you want. Real tags are a different story. Text such as <b>urgent</b> passes straight through as HTML, so it renders bold instead of showing the tag.
The fix is a backslash. The CommonMark spec lets you escape any ASCII punctuation character, so 5\*3\*2 comes out as 5*3*2 with no italics, and a line starting 2026\. stays a normal sentence. A leading \- keeps a dash from turning into a bullet. For longer literal text, wrap it in a code span or a fenced code block.
One limitation to know about: our Markdown to HTML tool and the editor apply Markdown rules to everything you paste. Neither has a plain-text mode or an option to escape raw tags. If your text contains HTML you want shown as text, run it through the script above instead.
Can You Add Headings and Lists? Markdown Is the Shortcut
Plain text carries no structure, so a converter can only guess where a heading starts. Markdown solves this by letting you mark structure with a few characters, which then become real tags:
## Agenda
- Budget review
- Hiring plan
That renders as an <h2> heading followed by a <ul> with two <li> items. Our Markdown to HTML converter runs in your browser and turns text like this into a full HTML document you can copy or download. It uses the marked library with single line breaks kept as <br>, so the newline behaviour matches the script above.
Try it below. The demo starts with the plain-text traps from the previous section, shows their backslash fixes, then adds a heading and a list on purpose:
For other routes from Markdown, including Pandoc and JavaScript libraries, see how to convert Markdown to HTML. If you're deciding whether to write the HTML yourself, our Markdown vs HTML comparison covers when each one fits.
Quick Answers on Converting Plain Text
Whichever route you pick, a text to HTML converter has four jobs: wrap paragraphs, keep the line breaks that matter, escape & and <, and link URLs. Use the script when the text is plain or private. When you also want headings and lists, write it as Markdown and convert it in the editor, where the live preview shows the result as you type.