Skip to main content
All In One PK

HTML Encode

Encode plain HTML to encoded HTML.

What this tool does

If you put a raw < into HTML, the browser thinks a tag started. Encoding replaces the special characters with entities such as &lt; and &amp;. You want that when you display code, a user's name, or a search query inside a page. You do not want it when you are trying to insert a real tag.

Encode data, not the tags you mean to keep. A common mistake is encoding a whole snippet that includes a real <a> or <strong> you wanted the browser to honour. Encode the untrusted piece, then wrap it in the tags you wrote yourself. Attributes need encoding too: a quote inside a title attribute will break the attribute if you only escaped angle brackets.

How to use HTML Encode

  1. Paste the plain text that should appear literally.
  2. Encode and check that angle brackets became entities.
  3. Paste the entities into your HTML body or attribute.
  4. Load the page and confirm you see the characters, not a broken layout.

When people actually use it

  • Showing a code sample

    A tutorial that prints <div> must encode it or the browser will create a div. Encode the sample, then wrap it in pre or code.

  • Usernames in a template

    A display name with < or & can break the page or worse. Encode it before you concatenate HTML.

  • Error messages

    A parser error that includes the bad token should be encoded before you render it in a status page.

  • Email HTML

    A subject line is plain text, but the HTML body is not. Encode the parts that are data, not tags.

Questions people ask

When should I encode HTML?

When you need to display HTML as text (e.g. in a tutorial) or escape special characters so they don’t break markup.

What gets encoded?

Characters like <, >, &, and quotes are turned into entities (e.g. &lt; &gt; &amp;).

Is my HTML stored?

No. Encoding runs in your browser; we don’t see or save your content.

Related tools

From the blog