html

How to add reserved characters in HTML

The reserved characters refer to those that are parsed by the browser as HTML code. These characters include <, >, &, and “. Whenever you use one of them, it will be considered as a part of HTML. So, if you want to get these characters in an output you have to use the entity names, HEX code, or entity number of that respective character. This article will provide the following learning outcomes:

– reserved characters in HTML

– how to use reserved characters in HTML

Reserved characters in HTML

This section lists down the reserved characters in HTML and provides the entity names of each reserved character.

< is referred to as the opening tag character.

> tends to close an HTML tag.

is used to enclose the value of an attribute, such as style=”background-color: blue;”.

& used to refer to an entity number or entity name, such as “&lt;” represents the “<” character.

Until now, we have gone through the reserved characters in HTML. Let’s practise them in HTML

How to use reserved characters in HTML

To use the reserved characters, we have to use the entity name, entity number, or HEX code of the characters that are provided in the following table.

Character HEX Code Entity Number Entity Name
< < < &lt;
> > > &gt;
" " &quot;
& & & &amp;

This section provides several examples to add reserved characters in various scenarios.

Example 1: Using HEX code to add reserved characters

The code provided below adds the reserved characters in HTML using their HEX code.

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title> Reserved Characters </title>

</head>

<body>

<h2> Using HEX value to add reserved characters </h2>

<p> The expressions 5<10 & 8>4 are "true"</p>

</body>

</html>

– In the paragraph tag, several expressions are exercised that use the HEX values of <, >, &, and “. The HEX code will print the symbols in the

Text Description automatically generated

Output

Text Description automatically generated with medium confidence

The output shows that each HEX value is changed to the respective reserved character.

Example 2: Using Entity number to add reserved characters

The code written below is practiced using the entity number to add reserved characters to HTML.

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title> Reserved Characters </title>

</head>

<body>

<h2> Using Entity Number to add reserved characters </h2>

<p> symbol of less than: <</p>

<p> symbol of greater than: ></p>

<p> symbol of ampersand: &</p>

<p> symbol of double quotes: "</p>

</body>

</html>

– a heading is created using h2

– four paragraphs are used to exercise the entity numbers of reserved characters to get them on screen

Text Description automatically generated

Output

Graphical user interface, text Description automatically generated with medium confidence

The output shows that the entity numbers are converted into respective reserved characters.

Example 3: Using Entity names to add reserved characters

This example practices the entity names to add the reserved characters in HTML.

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title> Reserved Characters </title>

</head>

<body>

<h2> Using Entity Name to add reserved characters </h2>

<p> less than: &lt;</p>

<p> greater than: &gt;</p>

<p> ampersand: &amp;</p>

<p> double quotes: &quot;</p>

</body>

</html>

The above code contains,

– a heading tag h2 to represent the

– four paragraphs are created in which the entity names are used to add reserved characters in HTML

Text Description automatically generated

Output

Text Description automatically generated with medium confidence

It is observed from the output that the entity names of the reserved characters have added their symbols in HTML.

Conclusion

The reserved characters in HTML assist in creating an HTML document. These characters are considered as HTML code by the browsers. To get these characters in an output, you would have to use the entity name or entity number of that reserved character. This guide has provided the list of reserved characters in HTML and also demonstrated the ways to add reserved characters in HTML.

About the author

Adnan Shabbir