HTML Part 3
HTML Part 3
In an HTML document, the <head> is a special section that doesn’t appear directly on
the webpage when it loads. Instead, it contains important information about the page,
called "metadata." This information helps browsers know how to display the page and
makes the page easier to search or share. For example, it holds the page title, links to
CSS files for styling, and other details like the document's author or keywords.
Here’s an example of a simple HTML document that shows the <head> and its
contents:
html
Copy code
<!doctype html><html lang="en-US">
<head>
<meta charset="utf-8" />
<title>My Test Page</title>
</head>
<body>
<p>This is my page</p>
</body></html>
In this example:
The <meta charset="utf-8" /> tag defines the character encoding, ensuring the page can
display text from different languages.
The <title> tag is the title of the page, which shows up in the browser tab.
Adding a Title
The <title> tag is used to set the title of your webpage. This title is shown on the
browser tab and in bookmarks. For example, the title "My Test Page" will appear on
the tab when you open the page.
But remember, the <title> is different from the <h1> tag, which adds a heading on the
webpage itself.
The <meta> tag is used to add extra information about your webpage, known as
"metadata." Here are a few common uses:
1.
Character Encoding: This tells the browser which character set to use. For
example, utf-8 is a universal character set that supports many languages,
making your page compatible with languages like English and Japanese.
2.
3.
html
4.
5.
Copy code
6.
7.
8.
9.
10.
Author and Description: You can use the <meta> tag to specify the author of
the page and add a short description. This can help improve the page's
visibility in search engines.
11.
12.
html
13.
14.
Copy code
15.
16.
17.
18.
19.
Search Engine Optimization (SEO): The description and title tags can help
your page rank higher in search engine results. When someone searches for
your site’s topic, the title and description will be shown in search results.
20.
html
Copy code
<link rel="icon" href="favicon.ico" type="image/x-icon" />
You can also add different icons for different devices, such as Apple devices:
html
Copy code
<link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon.png" />
To style your webpage or add interactive features, you can include CSS and
JavaScript files in the <head>:
CSS: Use the <link> tag to add a CSS file for styling.
html
Copy code
JavaScript: Use the <script> tag to add JavaScript functionality. The defer
attribute makes sure the script loads after the HTML content, preventing errors
if the script tries to use HTML elements that aren’t loaded yet.
html
Copy code
Summary
In summary, the <head> section of an HTML document holds important metadata and
links to external resources, such as CSS and JavaScript files. It helps the browser
understand how to render the page, and it also affects how the page appears in search
results and on social media. Some key elements in the head include: