HTML Encoding, also known as character encoding, is a way of representing characters that cannot be displayed directly in HTML by using special codes called entities.

This is necessary because not all characters can be represented in the limited character set used by HTML.

Type of HTML charset

In HTML, there are two types of character encoding: numeric and named entities. Numeric entities are represented by a number code, while named entities use a name for the character.

Here is an example of a named entity:

<p>This is a copyright symbol: <strong>&copy;</strong></p>

Here is an example of a numeric entity:

<p>This is a Greek alpha symbol: <strong>&#945</strong></p>

In both cases, the entity is represented by an ampersand (&), followed by either the entity name or a pound sign (#) and the numeric code, and ending with a semicolon (;).

In both cases, the entity is represented by an ampersand (&) followed by either the entity name or a pound sign (#)and the numeric code, and ending with a semicolon (;).

It's important to note that the character set used by HTML can affect how characters are displayed in the browser.

By default, HTML5 uses the UTF-8 character set, which supports a wide range of characters from different languages and scripts.

However, if you need to use a different character set, you can specify it using the "charset" attribute in the "meta" element, like this:

<meta charset="ISO-8859-1">

This specifies the ISO-8859-1character set, which supports a different set of characters than UTF-8.

It's important to ensure that the character set specified in your HTML document matches the character set used by your server and any external resources used in your page, such as stylesheets and scripts.

The HTML charset Attribute

The charset attribute in HTML specifies the character encoding used in the document. This attribute is declared in the <meta>tag within the <head> section of an HTML document.

The charset attribute value must be a character encoding name registered with the Internet Assigned Numbers Authority (IANA).

Example

<!DOCTYPE HTML>
  <html>
    <head>
      <meta charset="UTF-8">
      <link rel="stylesheet"  href="style.css"/>
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <title>Title of the Document</title>
    </head>
    <body>
      <p>Hello World!</p>
      <p>This is my webpage.</p>
      <p>Here is an example of a named entity:</p>
      <p>This is a copyright symbol: &copy; </p>
      <p>Here is an example of a numeric entity:</p>
      <p>This is a Greek alpha symbol: &#945;</p>
    </body>
</html>

In the above example, the charset attribute is set to "UTF-8", which is a widely used character encoding for Unicode. This tells the browser how to interpret the characters in the HTML document.

It is important to set the charset attribute correctly in order to avoid character encoding issues that can cause problems with displaying special characters or non-English text on the webpage.

HTML Uniform Resource Locators is very important when it comes to working with URL in the website you will learn more about it in the next chapter.