w3resource

HTML5: How to specify the character encoding for the HTML document?

Go to Exercise page

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

Firefox logo Chrome logo Opera logo Safari logo Internet Explorer logo
Yes Yes Yes Yes Yes

Go to Exercise page

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/html-css-exercise/basic/meta-charset-answer.php