In HTML, character encoding is specified using the <meta>
tag within the <head>
section of an HTML document. The character encoding declaration informs the browser about the character set used in the document, which helps ensure that the text is displayed correctly. The most commonly used character encoding is UTF-8, which supports a wide range of characters from various languages.
Here's an example of how to set the charset in HTML:
html<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Your HTML Document</title>
</head>
<body>
<!-- Your HTML content goes here -->
</body>
</html>
In the example above:
The <meta charset="UTF-8">
tag declares that the document is encoded using UTF-8.
The <meta name="viewport" content="width=device-width, initial-scale=1.0">
tag is optional and is often included to ensure proper rendering on various devices by setting the viewport width and initial scale.
Now, let's consider an example of how to use special characters in your HTML document:
html<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Special Characters Example</title>
</head>
<body>
<h1>Special Characters</h1>
<p>Here are some examples of special characters:</p>
<ul>
<li>© Copyright</li>
<li>& Ampersand</li>
<li>< Less than</li>
<li>> Greater than</li>
<li>€ Euro</li>
</ul>
</body>
</html>
In this example:
©
represents the copyright symbol.&
represents the ampersand symbol.<
represents the less-than symbol.>
represents the greater-than symbol.€
represents the Euro currency symbol.By using the appropriate character entities, you can include special characters in your HTML document, and the specified character encoding ensures that these characters are displayed correctly across different browsers and platforms.