# HTML and Text Converter

> Turn plain text into safe HTML paragraphs with & and < escaped, or strip tags from HTML and decode entities back to readable text.

Use it online (free, runs in your browser): https://directory.milunir.com/text-tools/text-editors/html-and-text-converter/

Pick Text to HTML to wrap your text in p tags, add br at single line breaks and escape the five special characters, so Fish & chips becomes Fish &amp; chips. Pick HTML to text to remove tags, scripts and comments and decode references like &nbsp; back into plain characters.

Pasting a product note into a CMS source view, or copying text out of an email template, both run into the same snag: markup and plain text use different rules for the ampersand, the angle brackets and line breaks. This converter works both ways. Text to HTML escapes every special character and turns empty lines into separate paragraphs, ready to paste into a template. HTML to text drops the tags, throws away script and style blocks, keeps list items on their own lines with a dash, and decodes named and numeric character references. Everything runs in your browser; the markup is never sent anywhere. One limit: it is a cleaner, not a full browser engine, so CSS that hides elements is ignored and their text still appears.

## How to use

1. **Pick a direction**: Choose Text to HTML or HTML to text at the top of the widget.
2. **Paste or open a file**: Paste into the box, or open a .txt or .html file from your device; it is read locally.
3. **Copy the result**: The converted markup or text appears in a code box as you type; use its Copy button.

## Examples

### A price line with & and

- Mode: Text to HTML
- Plain text: Fish & chips < £5

Result: Converted result: Fish & chips < £5

The ampersand and the less-than sign would break the markup, so they become &amp; and &lt;; the pound sign is left as it is.

### A paragraph with entities

- Mode: HTML to text
- HTML markup: Tom & Jerry <3

Result: Converted result: Tom & Jerry

Both tags go, and &amp;, &nbsp; and &lt; turn back into the characters they stand for.

### A menu note with two paragraphs

- Mode: Text to HTML
- Plain text: Fish & chips: £5 Peas < £1 Open 12–2pm

Result: Converted result: Fish & chips: £5 Peas < £1 Open 12–2pm

The empty line splits the note into two p elements, the single break becomes br, and & and < are escaped so the markup stays valid.

## How it works

`Text to HTML: & → &amp;, < → &lt;, > → &gt;, " → &quot;, ' → &#39;; blank line = new p element. HTML to text: tags removed, character references decoded per the WHATWG named references table`

In Text to HTML mode the input is split at empty lines. Each block becomes one p element, and a single line break inside a block becomes a br. Before wrapping, each line is escaped using the WHATWG serialization rules, plus quote escaping so the output is also safe inside attributes. In HTML to text mode, comments and script, style, head and template blocks are removed with their content. Runs of whitespace collapse to one space, as a browser renders them. Block tags such as p, div, headings and table rows become line breaks, li starts a line with a dash, and table cells are separated by tabs. Finally named references such as &mdash; and numeric ones such as &#215; or &#x3D; are decoded.

Sources:

- [HTML Standard – Serializing HTML fragments](https://html.spec.whatwg.org/multipage/parsing.html#serialising-html-fragments), WHATWG
- [HTML Standard – Named character references](https://html.spec.whatwg.org/multipage/named-characters.html), WHATWG

## When not to use it

- Rich formatting such as bold, links or headings is not created from plain text; only paragraphs and breaks are.
- Pages built by JavaScript need a real browser; this reads only the markup you paste.
- Sanitizing untrusted HTML for display on a site calls for a dedicated sanitizer library, not text extraction.

## Common mistakes

- Pasting already escaped text into Text to HTML, which turns &amp; into &amp;amp;.
- Expecting a single line break to start a new paragraph; leave an empty line instead.
- Forgetting that text hidden with CSS display none still appears in the plain text output.

## Questions

### Is there an HTML to text editor that keeps line breaks?

Yes. In HTML to text mode, p, div, headings and table rows each end a line, br becomes a line break and every li starts a new line with a dash. Extra blank lines are trimmed to one, so the output reads like the page did, without any tags left behind.

### How can I view HTML as plain text, like a text viewer?

Paste the source into HTML to text. The result box shows only what a reader would see: tags, comments, scripts and styles are gone, and entities such as &copy; or &mdash; appear as the real symbols. It is a quick way to read an email template or a saved page without opening it in a browser.

### How do I turn text into HTML code?

Choose Text to HTML and paste your text. Each block separated by an empty line becomes a p element, single breaks become br, and the characters &, less-than, greater-than and both quote marks are escaped. Copy the code box and paste it into your page source or CMS HTML view.

### Can I convert a text file to HTML?

Use Open a text file in Text to HTML mode to load a .txt or .md file; it is read inside your browser and never uploaded. The output is a body fragment of p elements, so paste it between the body tags of a page and save that as a .html file.

### Does this work like the Html to text action in Power Automate?

It follows the same idea: tags are dropped and the readable text is kept. It is handy for checking what an Outlook email body will look like after that flow step, or for cleaning one message by hand. It is a web page, not a connector, so it cannot run inside a flow.

## Use from code or an AI agent

Free JSON API, no key needed. The answer is in `result.stats.primary`.

```bash
curl -X POST https://api.tools-directory.workers.dev/v1/tools/html-and-text-converter \
  -H 'Content-Type: application/json' \
  -d '{"inputs":{"mode":"to_html","text":"Fish & chips < £5"}}'
```

- Inputs (JSON Schema): https://directory.milunir.com/api/v1/tools/html-and-text-converter.json
- MCP server: https://api.tools-directory.workers.dev/mcp (tool `html_and_text_converter`)
- Docs: https://directory.milunir.com/docs/
