YouTip LogoYouTip

Html Entities

```html HTML Character Entities | Novice Tutorial

HTML Character Entities | Novice Tutorial

Novice Tutorial -- Learning is not just about technology, but also dreams!

HTML Tutorial

HTML Tutorial HTML Introduction HTML Editors HTML Basics HTML Elements HTML Attributes HTML Headings HTML Paragraphs HTML Text Formatting HTML Links HTML Head HTML CSS HTML Images HTML Tables HTML Lists HTML Blocks HTML Layouts HTML Forms HTML Iframes HTML Colors HTML Color Names HTML Color Values HTML Scripts HTML Character Entities HTML URL HTML Quick List HTML Tag Abbreviations and Full Names HTML Summary HTML Quiz XHTML Introduction

HTML5

HTML5 Tutorial HTML5 Browser Support HTML5 New Elements HTML5 Canvas HTML5 SVG HTML5 MathML HTML5 Drag and Drop HTML5 Geolocation HTML5 Video HTML5 Audio HTML5 Input Types HTML5 Form Elements HTML5 Form Attributes HTML5 Semantic Elements HTML5 Web Storage HTML5 Web SQL HTML5 Web IndexedDB HTML5 Application Cache HTML5 Web Workers HTML5 SSE HTML5 WebSocket

HTML Character Entities

In HTML, some characters are reserved. For example, the less-than sign (<) and greater-than sign (>) are used to define HTML tags. If you want to display these reserved characters correctly, you must use character entities in the HTML source code.

Character entities are referenced in three ways:

  • Entity name: &entity_name; (e.g., &lt; displays <)
  • Entity number (decimal): &#number; (e.g., &#60; displays <)
  • Entity number (hexadecimal): &#xnumber; (e.g., &#x3C; displays <)

Note: Although entity names are easier to remember, not all browsers support the latest entity names. Entity numbers, on the other hand, are more widely supported.

Commonly Used HTML Character Entities

Display Result Description Entity Name Entity Number
< less-than &lt; &#60;
> greater-than &gt; &#62;
& ampersand &amp; &#38;
" double quotation mark &quot; &#34;
' single quotation mark (apostrophe) &apos; &#39;
¢ cent &cent; &#162;
£ pound &pound; &#163;
¥ yen &yen; &#165;
euro &euro; &#8364;
© copyright &copy; &#169;
® registered trademark &reg; &#174;
  non-breaking space &nbsp; &#160;

More complete entity references can be found in the HTML Entity Reference Manual.

Non-breaking Space (nbsp)

A non-breaking space (&nbsp;) is a space that will not break into a new line. Two words separated by a non-breaking space will stay together on the same line. This is useful when you do not want a line break to occur (e.g., between a number and its unit).

Example: 10 km/h

Using Character Entities in HTML

To display a less-than sign in a paragraph, use the following code:

<p>The less-than sign: &lt; </p>

The above code will display: The less-than sign: <

Important Note

When writing HTML, always use character entities for the following characters to avoid parsing errors: <, >, &, ", and '. In attribute values, double quotes should be escaped as &quot; and single quotes as &apos;.

Example of escaping attribute:

<a href="#" title="He said &quot;Hello&quot;">Link</a>

Browser Compatibility

All modern browsers support character entities. However, entity names introduced in newer versions of HTML may not be recognized by older browsers. For maximum compatibility, use decimal or hexadecimal entity numbers.

```
← Html UrlQuality Tutorial β†’