How Do You HTML Encode the Greater Than Sign (>)?

The html encoding of ">" is &gt;. The greater-than sign (>) is HTML encoded as &gt;. While browsers can often render an unescaped > correctly (unlike <), encoding it is required inside attribute values and is best practice everywhere to prevent XSS vulnerabilities and ensure valid HTML.

Why Encode ">"?

The > character closes HTML tags. While a bare > in text content is usually rendered correctly by browsers, encoding it as &gt; ensures valid markup, passes HTML validation, and prevents potential injection vulnerabilities when combined with other characters in user-generated content. Always encode both < and > together for consistency. In XHTML (which follows stricter XML rules), unescaped > in text content can cause parsing errors.

Encoding Details

Character>
Encoded form&gt;
Encoding typeHTML encoding
Unicode code pointU+003E

Code Examples

JavaScript

// Using built-in text content (auto-escapes)
element.textContent = '5 > 3';

// Manual encoding
'5 > 3'.replace(/>/g, '>');
// "5 > 3"

Python

import html
html.escape('5 > 3')
# '5 > 3'

Try It Yourself

Use our HTML Encoder to encode any character instantly.

Frequently Asked Questions

Is it really necessary to encode >?

Technically, the HTML5 spec allows unescaped > in text content nodes. However, best practice is to always encode it. Attribute values, XHTML documents, and XML contexts require proper encoding, and consistent escaping prevents XSS vulnerabilities and HTML validation errors.

What is the numeric code for >?

The greater-than sign can also be encoded as &#62; (decimal) or &#x3E; (hexadecimal). The named entity &gt; is more readable and widely preferred. All three forms are semantically identical and supported by every browser.

How do I display HTML code in a web page?

Encode both < as &lt; and > as &gt;. For example, to show a div element, write &lt;div&gt; in your HTML source. Alternatively, use the pre and code elements with proper encoding for displaying code blocks with syntax highlighting.

Built by Michael Lip. 100% client-side — no data leaves your browser.