HTML charset is also known as HTML character set and HTML encoding. It is used to display the alphabets, numbers, and some other symbols correctly on a webpage.
A web browser must know the character set used in an HTML page to display the HTML page correctly.
The charset attribute of the <meta> tag is used to specify the charset in HTML5.
<!DOCTYPE html> <html> <head> <!-- Charset --> <meta charset="UTF-8"> <title>Page Title</title> </head> <body> ... </body> </html>
There are various types of HTML Character Encoding, such as – 1) ASCII, 2) ANSI, 3) ISO-8859-1, 4) UTF-8. And each character encoding type contains a set of characters.
If you use an X character encoding type in your HTML page and write a character that is not available in the X character set, then the character will not display properly in your HTML page.
The Trademark symbol (™) is not available in ISO-8859-1, but it is available in UTF-8.
<!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>ISO-8859-1 Charset</title> </head> <body> Trademark Sign in ISO-8859-1 - ™ </body> </html>
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>UTF-8 Charset</title> </head> <body> Trademark Sign in UTF-8 - ™ </body> </html>
The UTF-8 Unicode charset covers almost all characters and symbols in the world, that’s why this character encoding type is used on most websites, and the default character set for HTML5 is UTF-8.