The <head>
element in HTML is a container for metadata and other non-visible elements that are included in an HTML document. It is located between the opening <html>
tag and the opening <body>
tag.
Here are some common elements that can be included in the head of an HTML document:
<title>
: This element is used to specify the title of the document, which is displayed in the browser’s title bar.<meta>
: This element is used to provide additional information about the document, such as the character encoding, keywords for search engines, and descriptions for social media sharing.<link>
: This element is used to link to external resources such as stylesheets and icons.<style>
: This element is used to define styles for the document, either in the head or in-line in the HTML.<script>
: This element is used to include JavaScript code in the document.
Here is an example of a basic HTML document with a head element:
<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
<meta charset="UTF-8">
<meta name="description" content="This is my website.">
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Welcome to my website</h1>
<p>This is the main content of my website.</p>
<script src="script.js"></script>
</body>
</html>
In this example, the head element includes a title, a character encoding meta tag, a description meta tag, and a link to an external stylesheet. The body element includes the main content of the website and a script tag linking to an external JavaScript file.