Lesson 10: HTML Metadata & The Document Head
HTML Metadata & The Document Head
Lesson 10 · Understanding what happens behind the scenes.
What is the document head?
Every standard HTML document has two important sections: the head and the body.
The head contains information about the webpage. Most of this information isn't displayed directly on the page.
The body contains the actual content visitors see, such as headings, paragraphs, images, and buttons.
The title element
The <title> element gives your webpage its document title. This is commonly displayed in the browser tab.
For example, if you visit a website called HYPERLINK Education, its browser tab might display:
The charset attribute
Have you ever seen strange symbols or broken characters on a website? Character encoding helps browsers understand how text should be interpreted.
The most common choice for modern websites is UTF-8.
UTF-8 supports a huge range of characters, including letters, punctuation, and many symbols used across different languages.
The viewport meta tag
Websites can be opened on desktops, laptops, tablets, and phones. But a page designed for a large screen might not look right on a smaller one.
The viewport meta tag helps browsers display pages at the appropriate width for the device.
Let's break it down:
- width=device-width tells the browser to use the device's screen width.
- initial-scale=1.0 sets the initial zoom level.
The description meta tag
Search engines can use information from your webpage to help understand what it is about.
The description meta tag provides a short summary of the page.
A search engine may use this description when displaying your webpage in search results.
Learn HTML, CSS, and JavaScript with HYPERLINK Education.
Author and robots metadata
You can also provide information about the creator of a webpage.
Another useful meta tag is the robots directive. It can tell search engine crawlers whether they may index a page and follow its links.
- index allows the page to be considered for indexing.
- follow allows crawlers to follow links on the page.
- noindex asks crawlers not to include the page in search results.
- nofollow asks crawlers not to follow links on the page.
Adding a favicon
A favicon is the small icon that appears beside a website's title in a browser tab, bookmarks, and other browser interfaces.
You can also use an image file, such as PNG:
Linking CSS and JavaScript
Your HTML document can connect to external CSS and JavaScript files. This keeps your code organized and makes larger projects easier to maintain.
Connecting an external CSS file:
The rel attribute describes the relationship between the current document and the linked file. Here, it tells the browser that the file is a stylesheet.
Connecting an external JavaScript file:
The defer attribute tells the browser to download the script while parsing HTML and execute it after the document has been parsed.
Open Graph metadata
Have you ever shared a website link in a chat and seen a preview with a title, description, and image?
Many websites use a system called Open Graph to provide information for these previews.
These properties provide information such as:
- og:title — the title of the shared page.
- og:description — a short description.
- og:image — the image used in the preview.
- og:type — the type of content being shared.
A complete HTML document head
Now let's combine several of the things you've learned into one example.
Notice how the head contains settings, metadata, and file connections, while the body contains the visible webpage content.
Your turn: Create a website head!
Imagine you're building a website for a small online magazine. Your job is to write its HTML document head.
Your document should include:
- A UTF-8 character encoding declaration.
- A viewport meta tag.
- A title that says "My Online Magazine".
- A description of the magazine.
- An author meta tag.
- A favicon link.
- An external CSS file.
Use this starter template:
Test your knowledge!
Choose the correct answer for each question.