简体   繁体   中英

How to avoid <> in HTML?

I would like to paste into my HTML code a phrase

"<car>"

and I would like that this word "car" will be between <>. In some text will be

"<car>"

and this is not a HTML expression. The problem is that when I put it the parser think that this is the HTML syntax how to avoid it. Is there any expression which need to be between this?

You can use the "greater than" and "less than" entities:

&lt;car&gt;

The W3C, the organization responsible for setting web standards, has some pretty good documentation on HTML entities . They consist of an ampersand followed by an entity name followed by a semicolon ( &name; ) or an ampersand followed by a pound sign followed by an entity number followed by a semicolon ( &#number; ). The link I provided has a table of common HTML entities.

use &gt; for > and &lt; for <

$gt;car&lt;

you need to use special character .. To know more about Special Character link here

CODE:

<p>&quot;&lt;car &gt;&quot;</p>

OUTPUT:

 "<car>"

< = &lt; less than

> = &gt; greater than

The same applies for XML too. Take a look here, special characters for HTML .

If you really want LESS THAN SIGN “<” to appear visibly in page content, write it as &amp; , so that it will not be treated as starting a tag. Ref.: 5.3.2 Character entity references in HTML 4.01.

So you would write

&lt;car>

If you like, you can write “>” as &gt; for symmetry, but there is no need to.

But if you really want to put something in angle brackets, eg using a mathematical notation, rather than a markup notation (as in HTML and XML), consider using U+27E8 MATHEMATICAL LEFT ANGLE BRACKET “⟨” and U+27E9 MATHEMATICAL RIGHT ANGLE BRACKET “⟩”. They cause no problems to HTML markup, as they are not markup-significant. If you don't know how to type them in your authoring environment, you can use character references for them:

&#x27e8;car&#x27e9;

This would result in ⟨car⟩, though as always with less common special characters, you would need to consider character (font) problems .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM