HTML Encoder

Try HTML Encoder

HTML Encoder inputs

Loading calculator. If this message stays visible, enable JavaScript and reload.

The HTML encoder replaces five characters in a text string with HTML character references: ampersand, less-than, greater-than, double quote and apostrophe. Use it when preparing a literal text example that contains markup punctuation. The output keeps the remaining characters, spaces and line breaks in their original order.

For example, an ampersand becomes &, and a less-than sign becomes <. This operation changes representation; it does not encrypt the text, validate an HTML document or certify that a value is safe in every application context. Check where the result will be inserted before using it in a template.

Escaping five HTML-sensitive characters

What does the HTML encoder replace?

The HTML encoder applies a fixed mapping. It replaces every occurrence of the five target characters, including occurrences inside a sentence, a tag-like string or an existing character reference. The same replacement rule applies to every part of the input.

Input characterReturned textExample purpose
&&Represent an ordinary ampersand.
<&lt;Represent a less-than sign literally.
>&gt;Represent a greater-than sign literally.
Double quote&quot;Represent a quotation mark.
Apostrophe&#39;Represent a single quotation mark.

The apostrophe output is a numeric character reference. The others in this table are named references. Both forms are ways of representing characters in HTML. Different encoders may choose different equivalent spellings, so a byte-for-byte difference is not automatically a difference in the character eventually displayed.

This implementation does not convert every non-ASCII letter into a reference. Ordinary Unicode text such as an accented word remains text. It also does not replace slashes, equals signs, brackets or backticks. Treat the actual five-character mapping as the feature boundary.

How should I encode a literal text sample?

Decide whether the source is raw text or an already encoded representation. Keep an unmodified copy, especially when diagnosing a display problem. A small sample is usually easier to follow than a complete page containing several unrelated escaping layers.

  1. Copy the exact raw string you want represented.
  2. Paste it into Input text.
  3. Run the encoder.
  4. Inspect the five target characters in the returned string.
  5. Insert the result only into an appropriate destination context.
  6. Check the complete destination document or component.

If the aim is a tutorial that shows a tag, encode the tag as text. If the aim is to create a functioning element, encoding the entire tag prevents that source from acting as normal markup in a suitable HTML text context. Those are different authoring tasks.

A content management system may already escape text entered in a plain-text field. Manually encoding before that stage can add a second layer. Check the field's documentation or preview rather than assuming every editor expects the same representation.

Do not remove line breaks just to encode a multiline sample. They are retained by this operation. Whether a browser later displays them as separate lines depends on the destination markup and styling, which are outside the string replacement itself.

What do the checked examples return?

The examples were verified in code with explicit expected strings. The references shown in the output column are the actual text returned, rather than a promise that any destination will interpret it in the same way.

Input:
<b>A & B</b>

Returned text:
<b>A & B</b>

Here the tag brackets and ampersand change. The b, A and B letters, slash and spaces stay in place. The encoder does not inspect whether the tag is balanced or whether the element name is meaningful.

Input:
He said "it's fine".

Returned text:
He said "it's fine".

Both kinds of quote are included in the mapping. The punctuation outside those five characters is retained. This makes the output predictable for a sample containing mixed quotation marks without changing the wording.

A plain input such as Hello world returns Hello world. An input such as café 😀 also remains unchanged by this mapping. No target characters are present in either sample, so a result identical to the input is expected.

A source containing an existing &lt; sequence returns &amp;lt;. The original ampersand is encoded even though its neighbouring letters resemble an existing reference. That behaviour is central to understanding double encoding.

Why does encoding twice produce a different result?

The output includes ampersands because HTML references start with them. Running the encoder again replaces those ampersands. A raw less-than sign becomes the text &lt; after one pass and &amp;lt; after a second pass.

This is not a duplicate-removal process or an idempotent normalization. Each pass treats its entire input as a fresh raw string. The operation does not remember whether an earlier pass created any part of the source.

Double encoding can be intentional when documenting the spelling of a reference itself. To show readers the literal characters ampersand, l, t and semicolon in rendered HTML, the source needs to represent the ampersand. In that case, the additional layer has a clear purpose.

It is a problem when a value intended to display as a character instead displays as reference text. Trace the stages in the pipeline: original text, manual conversion, template escaping and final rendering. Correct the stage that owns the unwanted layer rather than repeatedly encoding and decoding until the preview happens to look right.

The HTML Decoder helps inspect recognized references. Use it on a copy while investigating. Decoding without understanding the destination can reintroduce syntax characters where a program should have kept them represented as text.

How does HTML encoding differ from URL, Base64 and JSON encoding?

The representation must match the syntax being used. A URL component, a JSON string and HTML text have different rules. An HTML reference is not a universal escape sequence that all formats understand.

Use the URL Encoder when the task is encoding a supported URL component under that tool's rules. A sequence such as percent followed by hexadecimal digits belongs to a different representation from an HTML character reference.

The Base64 Encoder produces a different text representation again. Base64 output does not make a value secret, and decoding it does not apply HTML parsing rules. Choose it only when the receiving system specifies that format.

For structured JSON, use JSON serialization in the application and the JSON Validator to inspect an existing JSON text. Replacing quotation marks with HTML references does not produce the backslash escapes required inside a JSON string.

If several representations are nested, record their order. For example, a URL value may appear inside an HTML attribute in a larger document. The application should build and encode each layer according to that layer's syntax. A single manual conversion cannot infer that structure from a raw string.

Does this make untrusted HTML safe?

This tool performs a fixed text replacement. It is not an HTML sanitizer that accepts some elements and removes others, and it does not inspect a whole application for unsafe insertion points. Avoid treating the result as a general security certificate.

OWASP explains that output handling depends on context, including HTML text, attributes, JavaScript, CSS and URLs. It also distinguishes encoding from sanitization. Use the protections designed for the actual destination and prefer the framework's established rendering facilities over improvised manual concatenation.

The OWASP XSS prevention guidance is the primary reference for that distinction. The limited conclusion here is that escaping five characters cannot by itself assess an entire document, a URL policy or an application's use of the returned value.

If the requirement is allowing selected formatting from users, use an appropriate maintained sanitization workflow with a clear content policy. If the requirement is displaying a plain string, use a destination that treats it as text. These choices belong in the application design, not in guesswork based on how encoded text looks.

Security-sensitive examples and decisions should be reviewed in the real application. This page describes a conversion utility; it is not a personalised security assessment. Refer to the official guidance and test the complete component before deployment.

How can I check the result in a content workflow?

Keep the distinction between source and rendered display visible during review. The source can contain a reference while the browser displays the represented character. A screenshot of the display alone does not reveal which source spelling produced it.

Use a short sample containing all five target characters. Confirm that each is represented once and that ordinary letters are unchanged. Then test the same sample through the editor, template or component that will use it.

The Character Counter can help demonstrate that encoded text often has more characters than its source. A reference is several visible source characters representing one eventual character. A larger output length is therefore expected and does not mean extra prose was added.

For a tutorial, label the original text and encoded source separately. Use preformatted display when line breaks or multiple spaces matter. Ordinary HTML layout can collapse whitespace, so a correctly encoded string may still appear with different spacing unless the destination preserves it.

When a translation or editorial team handles the text, retain raw content as the editable source where the system expects it. Manually editing a mixture of raw characters and references can create inconsistent layers. Establish which stage escapes the content and keep that responsibility clear.

A useful review question is whether the destination already knows the value is text. If it does, an additional manual pass may only make the visible result less readable. Preview the complete publication and check its stored source before deciding that more escaping is necessary.

What limits and privacy details matter?

The underlying text helper rejects input beyond 500,000 JavaScript string units. Encoded output may be longer than the source because one character can become several characters. A limit on input size is not a guarantee that every device will comfortably display an extremely large result.

The operation runs in the browser and does not need to retrieve an input URL. That describes its computation. Broader website delivery and data practices are covered by the MoneyOr privacy policy. Use artificial snippets when testing a general conversion question.

The HTML Standard's character-reference section describes the underlying syntax. The tool uses only the five replacements listed above, not every named reference available in HTML.

Save raw source, expected encoded text and final rendered display separately when reproducibility matters. That record makes an escaping problem easier to locate and prevents an encoded example from being mistaken for the original user-facing wording.

Choose this encoder for its exact replacement rule. Let the receiving application decide how to handle text in its own context, and verify the full path from the original string to what the reader sees.

A content editor can also show a different view to the person writing a page and the person reading it. In an editor that has both a visual mode and a source mode, the source mode may display character references for text that looks ordinary in the visual mode. If the reader is meant to see the words Tea & toast, preview the page and inspect that exact spot. The markup and the visible wording can legitimately differ. A visible &amp; in the finished page is a sign that the reference itself is being shown, which is correct for some tutorials and wrong for an ordinary menu label.

Use a small reference fixture when a value moves between tools. Include a row with an ampersand, another with a quotation mark and a plain row that needs no replacement. Record the raw text, encoded text and expected visual result. This lets you rerun the same comparison after a template update. If the untouched row changes, look for another operation in the content pipeline, such as an editor applying its own typography. If only the encoded rows change, inspect how the receiver treats references.

Keep indentation separate from punctuation. This encoder leaves line breaks and spaces alone. A browser displaying HTML may still collapse a series of spaces in an ordinary paragraph. If your tutorial depends on the layout of a sample, choose a preformatted block in the receiving editor and verify its source handling. Several lines in your input can stay several lines in the encoded string even when the page displays them on a single flowing line.

When sharing a fixture with someone else, name the form each cell contains. A file labelled simply “escaped sample” might contain a literal reference, encoded data intended for injection into a trusted template, or the final visual transcription. Giving each column a precise label helps the next reviewer copy the right representation.

Frequently asked questions

Why does an ordinary sentence return unchanged?

A sentence with none of the five target characters needs no replacement under this mapping. The tool does not rewrite words, remove accents or turn every character into a numeric reference.

Is an apostrophe encoded as apos?

This implementation returns the numeric reference &#39;. Another encoder may use a different equivalent form. Compare the intended character and destination syntax rather than assuming only one textual spelling can be valid.

Does it remove tags from a string?

No. It represents their punctuation as text. The letters and other characters remain. Removing markup while extracting readable content is a separate parsing task with different behaviour for structure and whitespace.

Will it repair a broken page?

No. It does not inspect a page structure, missing closing tag or template error. Use it to examine a known string; diagnose the complete document with the appropriate validator and application tools.

Can I use it instead of my template engine's escaping?

Use the template engine's documented protection for the actual insertion context. A manual utility cannot determine how every value will be used later, and an extra pass can create unwanted double encoding.