Javatpoint Logo
Javatpoint Logo

Entities in HTML

What is Entity?

A text fragment (or "string") that starts with an ampersand (&) and ends with a semicolon (;) is known as an HTML entity. Entities are widely used to show unseen characters, such as non-breaking spaces and reserved characters, which would be read as HTML code. Additionally, you may substitute them for other characters that are challenging to enter on a regular keyboard.

Reserved Characters

Our browser will read some special characters as HTML code since they are reserved for usage in HTML. For instance, the browser understands any text that follows the less-than (<) sign as a tag.

Replace these characters with their respective character entities as indicated in the following table to display them as text.

Symbol Description Entity Name Number Code
" Quotation mark &quot; &#34;
' Apostrophe &apos; &#39;
& Ampersand &amp; &#38;
< Less-than &lt; &#60;
> Greater-than &gt; &#62;

Implementing an Entity

You can refer to an entity by name or a numeric character reference in your HTML content. Each entity has an ampersand (&) at the beginning and a semicolon (;) at the end.

Syntax:

Write &lt; or &#60; to indicate a less than symbol (<).

  • A benefitof utilizing entity names is that they are simple to recall.
  • A drawback of utilizing an entity name is that not all entity names may be supported by browsers, whereas entity numbers often are.

The following table lists the five special characters that HTML processors must support.

Example

We must provide the following code if you wish to write "div id = <"character"> as a code:


Character Entities
&GreaterEqual;
© &copy;
&euro;
&exist;
&trade;
® &reg;

Example: This example displays the usage of special characters that are directly unavailable to type from the keyboard.

Output:

Entities in HTML

Benefits of HTML Entity

  • Names of entities may be simple to recall.

Disadvantages

  • Browsers may support using entity numbers rather than all entity names, though this is not guaranteed.

What is Non-breaking Space?

This type of space creates a line break without starting a new one. This HTML entity is represented by the character &nbsp;, which will divide the two words and keep them together without starting a new line.

The non-breaking space can also stop browsers from truncating spaces in HTML documents. A hyphen character () that does not start a new line is called a non-breaking hyphen ().

Example:

2:00 PM

300 km/h

The browser will eliminate 9 of the spaces if we used to put 10 of them in our text. The character entity may be used to add actual spaces to our text.

Adding Diacritical Marks

A "glyph" added to a letter is a diacritical mark. Accents are diacritical symbols such as grave ( ' ) and acute ( `). It may be positioned above, below, within, or between two alphabet letters. Diacritical marks can be used with alphanumeric characters to construct a character that does not exist in the character set (encoding) used on the page. The list of diacritical marks is provided below.

Symbols Character Construct Final Result
̀ a
́ a
̂ a
̃ a
̀ O
́ O
̂ O
̃ O

Adding HTML Entities with CSS Content

HTML provides a means for displaying reserved characters. Reserved characters are those characters that are either reserved for HTML or those which are not present in the basic keyboard.

For instance, the HTML language already reserves the character "." The coding often has uncertainty since this character must appear on the web page. Along with these are the characters (£, ¥, €, ©) that are typically absent from the standard keyboard. To utilize these symbols, HTML supplies some Entity names and Entity numbers. Learning entity numbers is simple.

Output:

Entities in HTML
Next TopicHTML Symbols





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA