HTML5: How to specify the character encoding for the HTML document?
Solution :
HTML Code:
<!DOCTYPE html><!-- Declares the document type and version of HTML -->
<html><!-- Begins the HTML document -->
<head><!-- Contains metadata about the document -->
<meta charset="utf-8"><!-- Specifies the character encoding for the document -->
<title>How to specify the character encoding for the HTML document</title><!-- Sets the title of the document -->
</head><!-- Ends the head section -->
<body><!-- Contains the content of the document -->
<h1>HTML meta tag and element</h1><!-- Represents a level 1 heading -->
<p>HTML meta element contains information about an HTML document.</p><!-- Represents a paragraph of text -->
</body><!-- Ends the body section -->
</html><!-- Ends the HTML document -->
Explanation:
- The HTML document begins with a declaration of its type and version (<!DOCTYPE html>).
- The <html> element encloses the entire HTML document.
- The <head> section contains metadata about the document.
- The <meta charset="utf-8"> tag specifies the character encoding for the document as UTF-8, which supports a wide range of characters from various languages.
- The <title> tag sets the title of the document, which appears in the browser's title bar or tab.
- The <body> section contains the main content of the HTML document.
- In this example, there is a level 1 heading <h1> and a paragraph <p> of text.
Live Demo:
See the Pen meta-charset-answer by w3resource (@w3resource) on CodePen.
See the solution in the browser
Supported browser
Yes | Yes | Yes | Yes | Yes |
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics