The <head>
tag in HTML is used to define the head section of a document, which contains meta-information about the document, such as the title, character set, linked stylesheets, scripts, and more. Here are some common elements that you can include within the <head>
tag along with examples:
Title Tag:
The <title>
tag is used to define the title of the HTML document. It appears on the browser tab or window.
html<!DOCTYPE html>
<html>
<head>
<title>My Web Page</title>
</head>
<body>
<!-- Content goes here -->
</body>
</html>
Meta Tags: Meta tags provide metadata about the HTML document, such as the character set, viewport settings, and keywords for search engines.
html<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="keywords" content="HTML, CSS, JavaScript">
</head>
<body>
<!-- Content goes here -->
</body>
</html>
Link Tag (for CSS):
The <link>
tag is used to link an external stylesheet to the HTML document.
html<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<!-- Content goes here -->
</body>
</html>
Script Tag (for JavaScript):
The <script>
tag is used to include JavaScript code within the HTML document, either inline or by referencing an external script file.
html<!DOCTYPE html>
<html>
<head>
<script src="script.js"></script>
</head>
<body>
<!-- Content goes here -->
</body>
</html>
Base Tag:
The <base>
tag specifies a base URL/target for all relative URLs in a document.
html<!DOCTYPE html>
<html>
<head>
<base href="https://example.com/">
</head>
<body>
<!-- Content goes here -->
</body>
</html>
These are some of the common elements that you can use within the <head>
tag to enhance and provide additional information about your HTML document. Remember that the <head>
section doesn't contain content visible to the user; it's more about document structure and metadata.