Let's say you are creating a new website for a client and you want to ensure that it is optimized for search engines. Your client is a small business that sells handmade jewelry. They want their website to rank high in search results when people search for "handmade jewelry" or related keywords. To achieve this, you would need to make sure that the <head> section of your HTML document includes relevant information about the website's content.
For example, you might include the following elements in the <head> section:
By including these elements in the <head> section of your HTML document, you are providing important information to search engines about the content of your website. This helps search engines understand what your website is about and makes it more likely that your website will appear in search results when people search for relevant keywords.
In this lesson, we will explore the head section in HTML and its various components.
Subtopics:
The head section is located between the opening and closing HTML tags and contains information about the web page that is not visible on the page itself. It is a container for metadata, which provides information about the page that is used by browsers and search engines. The head section also includes links to external resources such as stylesheets and scripts. The head section is enclosed by the <head>and </head>tags.
Example of head element:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<meta charset="UTF-8">
<meta name="description" content="A brief description of the page">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<!-- content of the page goes here -->
</body>
</html>
In this example, the head element contains several metadata elements, including:
These elements are all placed within the head element, which is located before the body element. The body element contains the actual content of the page, such as headings, paragraphs, images, and other HTML elements.
The title tag is one of the most critical components of the head section, and it defines the title of the web page. The text within the title tag is displayed on the browser's title bar and in search engine results. The title tag should be descriptive and contain relevant keywords that accurately reflect the content of the web page.
For example, suppose you are creating a web page about healthy recipes. In that case, the title tag could be:
<title>Healthy Recipes - Delicious and Nutritious</title>.
Meta tags are HTML elements that provide metadata about a web page. They are included in the head section of an HTML document and are not visible to the user. Meta tags can be used to provide information about the author of the page, the description of the page, keywords related to the content, the character set used on the page, and other information that can be useful for search engines and other web tools.
Some common types of meta tags include:
<meta name="description" content="Find healthy and delicious recipes for your family with our collection of healthy recipes.">
<meta name="keywords" content="healthy, recipes, family, nutritious, delicious">
Meta tags are important for several reasons:
Overall, meta tags are an important aspect of on-page SEO (search engine optimization) and can help to improve the visibility and ranking of a web page in search results.
Link tags are used to link the web page to external resources such as stylesheets, scripts, and icons. There are several types of link tags, including:
<link rel="stylesheet" href="style.css">
Stylesheet Link Tag: This tag is used to link the web page to an external stylesheet that defines the page's style and layout. For example,
Script Link Tag: This tag is used to link the web page to an external JavaScript file that contains code used to manipulate the page's content or behavior. For example,
<link rel="script" href="script.js">
Style tags are used to define the web page's style and layout. They can be used to change the font, color, and layout of the page's content.
For example,
<style>
body {
background-color: lightblue;
}
h1 {
color: white;
text-align: center;
}
</style>
Script tags are used to define and execute JavaScript code on the web page. They can be used to manipulate the page's content or behavior.
For example,
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Hello World!";
}
</script>
The HTML <base> element is used to specify the base URL for all relative URLs in a document. It must be placed in the <head> section of the document and can have two attributes:
Here is an example of how to use the <base> element in the <head> section of an HTML document:
<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
<base href="<https://example.com/>" target="_blank">
</head>
<body>
<a href="page.html">Page</a>
</body>
</html>
In this example, the <base> element specifies that all relative URLs in the document should be resolved against the URL https://example.com/. The target attribute specifies that all hyperlinks and forms should open in a new window or tab.
When a hyperlink is clicked or a form is submitted, the browser will use the base URL to resolve the relative URL in the href attribute of the hyperlink or the action attribute of the form. In this example, clicking the "Page" link will take the user to https://example.com/page.html.
Using the <base> element can be useful when working with a website that has a complex URL structure or when migrating a website to a new domain.
In conclusion, the head section in HTML is an essential component of any web page as it contains information about the page that is not visible to the user. It includes metadata, links to external resources, and scripts used to define the page's style and behavior. Understanding and properly utilizing the head section is crucial to creating effective and accessible web pages.
Top Tutorials
Related Articles