Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right angle bracket in HTML

Tags:

html

For obvious reasons, the left angle bracket cannot be used literally in HTML text. The status of the right angle bracket is not quite so clear. It does work when I try it, but of course browsers are notoriously forgiving of constructs that are not strictly valid HTML.

http://www.w3.org/TR/html4/charset.html#h-5.4 seems to be saying it's valid, though may not be supported by older browsers, but also makes specific mention of quoted attribute values. Is it necessary to html encode right angle brackets? also says it's valid but again specifically talks about quoted attribute values.

What's the answer for plain chunks of text (contents of a <pre> Element happens to be the case I'm looking at), and does it differ in any way?

like image 957
rwallace Avatar asked May 05 '12 13:05

rwallace


People also ask

How do you make a right angle bracket in HTML?

The character “>” is the GREATER THAN character. It is used in many contexts, like HTML markup, as a delimiter of a kind, in a bracket-like manner, but the real angle brackets, as used in some mathematical notations, are rather different, such as “⟩” U+27E9.

What is angular brackets in HTML?

Angle brackets are commonly used to enclose a code of some type. For example, HTML tags and PageMaker tags are enclosed in angle brackets. They are also used on chat channels and in chat rooms to frame a comment or expression, such as <groan!> or <g>, which is short for <grin>.

Why does HTML use angle brackets?

You can see that HTML contains pieces enclosed in angle brackets (' < ' and ' > '), which are also known as the less-than and greater-than symbols. Each of these angle-bracket-enclosed pieces, called a tag, does not appear to the user, but rather gives information about the page's structure.


2 Answers

The character “>” can be used as such as data character in any version of HTML, both in element content and in an attribute value. This follows from the lack of any statement to the contrary in the specifications.

It is often routinely escaped as &gt;, which is valid but not required for any formal or technical reason. It is used partly because people assume it is needed the same way as the “<” character needs to be escaped, partly for symmetry: writing, say, &lt;code&gt; may look more symmetric than &lt;code>.

The character “>” is the GREATER THAN character. It is used in many contexts, like HTML markup, as a delimiter of a kind, in a bracket-like manner, but the real angle brackets, as used in some mathematical notations, are rather different, such as “⟩” U+27E9. If you need to include angle brackets in an HTML document, you have some serious issues to consider, but they relate to fonts (and semantics), not to any potential clash with markup-significant characters.

like image 72
Jukka K. Korpela Avatar answered Sep 29 '22 08:09

Jukka K. Korpela


Right angle brackets are legal within a <pre> tag or as text within an element.

There is no ambiguity when using them in this manner and parsers have no issue with "understanding" them.

Personally, I just escape these whenever I need to use them, just to match left angle brackets...

like image 24
Oded Avatar answered Sep 29 '22 07:09

Oded