Greater than sign (>) in HTML
Unlike the less than sign, a bare greater than sign is valid in HTML text content. It still has to be escaped in comments, in XML and anywhere a closing sequence could form.
At a glance
- Character
- >
- Named entity
- >
- Decimal reference
- >
- Hex reference
- >
- Unicode code point
- U+003E
- Unicode name
- GREATER-THAN SIGN
- In the entity reference
- Math, and pinned in quick access
In detail
The asymmetry surprises people. A greater than sign that is not closing a tag is simply text, and <p>5 > 4</p> is valid HTML that renders correctly. The parser has already decided it is not inside a tag, so the character has nothing to close. Escaping it is a convention rather than a requirement in that position.
The contexts where it is required are narrower and easier to hit than they sound. Inside a comment the sequence of two hyphens followed by a greater than sign ends the comment, so a template that drops arbitrary text into a comment can be terminated early. In XML and XHTML the sequence of two closing square brackets followed by a greater than sign must be escaped because it ends a CDATA section.
Every serious escaping function outputs > regardless, and there is a good reason beyond caution. Encoding both directions makes the output symmetric, so a grep for an unescaped angle bracket is a single pattern rather than a special case, and a diff between two escaped strings does not vary depending on which way the bracket pointed.
The character also carries meaning that has nothing to do with markup. It is the quoting prefix in plain text email and in markdown blockquotes, and it is the shell redirection operator. When you are rendering any of those into a page, the greater than sign is content and needs encoding for exactly the same reason the less than sign does: so that a later processing stage cannot mistake it for syntax.
Examples
<p>The signature is <code>Map<string, number></code>.</p><!-- user note: rated 5 --> 4 stars -->
<!-- without the escape the comment would end at the arrow -->Things that catch people out
- Escaping the less than sign but not the greater than sign passes most tests and then fails on a comment or an XML feed, which is a hard failure with no visible warning beforehand.
- In an attribute value a greater than sign is legal, but an HTML minifier that later removes the quotes turns it into a tag terminator. Quote your attributes or escape the character.
- A right pointing chevron in navigation is usually a greater than sign pasted in by hand. A real arrow or a CSS border triangle reads better and does not get announced as a comparison by a screen reader.
Try it: HTML Entity Reference
Search 152 entities across 9 categories, switch the copy format between the character, the name, the decimal form and the hex form, and copy in one click.
HTML Entity Reference
LOCAL · Browser-OnlySearchable reference of 150+ HTML entities with one-click copy in any format
152 entities across 9 categories
Commonly Used
→Arrows(13)
±Math(35)
$Currency(8)
…Punctuation(21)
©Symbols(24)
πGreek(30)
½Fractions(6)
●Geometric(7)
æLatin Special(8)
Click any entity card to copy it in your chosen format. All data is embedded in the page and works offline.
Related HTML entities
All html entities →Less than sign (<) in HTML
A literal < starts a tag, so text containing it has to be written <. Where the parser recovers, where it does not, and why this is the core of escaping.
Ampersand (&) in HTML
The ampersand opens every character reference, so a bare & in markup is ambiguous. What & fixes, and the query string trap that quietly eats a parameter.
Right arrow (→) in HTML
The rightwards arrow at U+2192, its entity forms, using it in a call to action without confusing a screen reader, and how it behaves in right to left text.
Double quotation mark (") in HTML
The straight double quote ends an attribute value, so it needs " there. Where that matters, where it does not, and how JSON in a data attribute breaks.
Apostrophe (') in HTML
' is defined in HTML5 and XML but was absent from HTML 4.01. Why ' is the safer numeric form and when a single quote actually needs escaping.
Em dash (—) in HTML
The em dash at U+2014, its named, decimal and hex references, how it differs from the en dash and hyphen, and the practical reasons to prefer a comma.
Tools for this
- HTML Entity Reference Free online HTML entity reference - search and copy HTML entities with live preview
- HTML Entity Encoder Free online HTML entity encoder - encode or decode HTML entities to prevent XSS and display issues