Home / Learn HTML / Elements: Document and Metadata
Elements: Document and Metadata
Elements that build the page skeleton and give the browser information about it.
About this lesson
These elements build the skeleton of a page and carry information for the browser, search engines and social media. Most of them live in the head and are invisible. Each element below has a definition, the rules for using it, its attributes and a live example.
The <html> element
The html element is the root element. Every other element on the page lives inside it. It tells the browser that the file is an HTML document.
When to use it: Use it exactly once, right after <!DOCTYPE html>. It must contain one head followed by one body.
Why we use it
Every page needs one root. It tells the browser where the document starts and ends, and it carries the page language.
How it works
The browser builds the DOM tree from this element. The lang attribute helps screen readers pick the right voice and helps translation tools.
Where it is used
- Every web page on the internet
- Setting lang="en" or lang="hi" for the whole page
- Email templates and HTML documents
Common mistakes
Forgetting lang, or putting content outside html. Only head and body belong directly inside.
| Attribute | Meaning |
|---|---|
lang | language of the page (en, hi, fr) |
dir | text direction (ltr, rtl) |
lang. Screen readers pick the right voice from it and search engines use it to understand the page.The root of the page. Everything lives inside it.
The <head> element
The head element holds information about the page. None of it is drawn on the screen: the title, character set, links to style sheets, scripts and meta data.
When to use it: Use it once, as the first child of html. Put title, meta, link, style, script and base inside it. Never put visible content here.
Why we use it
It holds information about the page that visitors do not see on the page itself: title, encoding, styles and SEO tags.
How it works
The browser reads the head first. Nothing inside it is drawn in the page area, but it controls how the page behaves, looks and is shown in search results.
Where it is used
- Page title and meta description for SEO
- Linking CSS files and favicons
- Open Graph tags for share cards
Common mistakes
Putting visible content such as p or div in the head. The browser will quietly move it to the body.
Holds information about the page. Not shown.
The <title> element
The title element gives the page its name. It shows on the browser tab, in bookmarks and as the blue link in Google results.
When to use it: Use one unique title for each page. Keep it between 50 and 60 letters and put the important words first.
Why we use it
The title is the name of the page. It shows in the browser tab, in bookmarks and as the blue link in Google results.
How it works
The browser shows the text on the tab. Search engines use it as the main headline of the page. Only text is allowed, no tags.
Where it is used
- Browser tabs and history
- Google search results
- Social share fallback text
Common mistakes
Leaving it empty or using the same title on every page. Aim for 50 to 60 clear letters.
The page title on the tab and in search results.
The <meta> element
The meta element states information about the page that no other element can: the character set, the description, the viewport and settings for robots and social media.
When to use it: Place it in the head. It is an empty element, so it has no end tag. The pair name and content works together.
Why we use it
Meta tags give the browser and search engines facts about the page: character set, mobile width, description and more.
How it works
Each meta tag has a name and content pair (or charset). The browser or a crawler reads the pair and acts on it. It is never drawn on the page.
Where it is used
- charset UTF-8 so every language shows correctly
- viewport for mobile layouts
- description for search results
- robots to allow or block indexing
Common mistakes
Forgetting the viewport tag, so the page looks tiny on phones.
| Attribute | Meaning |
|---|---|
charset | character encoding (UTF-8) |
name | kind of information (description, viewport, robots) |
content | the value |
http-equiv | acts like an HTTP header |
property | used by Open Graph (og:title) |
meta charset and meta viewport. Without the viewport tag mobile pages look tiny.Information about the page: charset, description, viewport.
The <link> element
The link element connects the page to an outside file or address. It is mostly used for style sheets, icons and the canonical address.
When to use it: Place it in the head. It is an empty element. The rel attribute tells what kind of relation the file has to your page.
Why we use it
It connects the page to an outside file such as a stylesheet, an icon or a preload hint.
How it works
The rel attribute says what the relation is and href says where the file is. For rel="stylesheet" the browser downloads the CSS and applies it.
Where it is used
- Linking style.css
- Favicons with rel="icon"
- rel="canonical" for SEO
- Preloading fonts
Common mistakes
Writing a wrong href path so the stylesheet never loads. Check the Network tab.
| Attribute | Meaning |
|---|---|
rel | stylesheet, icon, canonical, preload, alternate |
href | address of the file |
type | file type |
media | when the file applies |
hreflang | language of the target |
as | kind of file for preload |
link is not the same as a. A link element is not clickable; it only connects resources.Connects the page to a file such as CSS or an icon.
The <style> element
The style element holds CSS written directly inside the page. The rules inside it change how the page looks.
When to use it: Use it in the head for rules that belong to one page. For a real site with many pages, put CSS in a separate file and use link.
Why we use it
It lets you write CSS directly inside the HTML file.
How it works
The browser parses the CSS text and applies the rules to matching elements.
Where it is used
- Small demo pages and email templates
- Critical CSS inlined for speed
- Quick tests in a live editor
Common mistakes
For big sites use an external file. Many inline style blocks are hard to maintain and cannot be cached.
| Attribute | Meaning |
|---|---|
media | applies the rules only on matching screens |
type | always text/css (can be left out) |
style element are overridden by an inline style attribute on an element.CSS written inside the page.
The <base> element
The base element sets one base address for all relative links and file paths in the page, and a default target for links.
When to use it: Use it once in the head, before any element that uses a relative address. It is rarely needed.
Why we use it
It sets one base address for all relative links and one default target for the page.
How it works
Relative URLs such as images/a.png are resolved against the href of base instead of the page address.
Where it is used
- Sites where all links share a base folder
- Setting target="_blank" for every link
Common mistakes
It changes every relative link on the page, including anchor links like #top. Use it carefully and only once.
| Attribute | Meaning |
|---|---|
href | the base address |
target | default target for links (_blank, _self) |
base breaks every relative link and image on the page, so use it with care.Sets one base address for every relative link.
The <script> element
The script element holds JavaScript code or links to a JavaScript file. It can also carry data, such as JSON-LD for search engines.
When to use it: Put it at the end of the body, or in the head with defer. Inline code goes between the tags; a file uses src.
Why we use it
It adds behaviour: clicks, calculations, data loading and animation.
How it works
The browser downloads and runs the code. Use defer so the script runs after the HTML is parsed and does not block drawing.
Where it is used
- Interactive menus and forms
- Analytics and ads
- Loading JavaScript files
Common mistakes
A blocking script in the head slows the page. Use defer or place scripts at the end of body.
| Attribute | Meaning |
|---|---|
src | address of a script file |
defer | run after the page is built |
async | run as soon as it downloads |
type | module or application/ld+json |
integrity | security hash |
defer or async a script in the head stops the page from showing until it has run.Holds JavaScript code or links to a JavaScript file.
The <noscript> element
The noscript element holds content that is shown only when JavaScript is turned off or not supported.
When to use it: Use it to show a polite message or a plain version of important content. It can go in the head (with link, style, meta) or in the body.
Why we use it
It shows a fallback message when JavaScript is turned off or not available.
How it works
If scripting is enabled the browser ignores its content. If disabled, the content is shown.
Where it is used
- A friendly message such as "Please turn on JavaScript"
- Fallback images for trackers
Common mistakes
Do not hide important content behind JavaScript only. Offer a basic version.
Shown only when JavaScript is off.
The <body> element
The body element holds everything people see on the page: text, images, links, forms and more.
When to use it: Use it once, after the head. Never place content outside it.
Why we use it
Everything that visitors see lives in the body: text, images, links, forms and more.
How it works
The browser draws the body inside the window. It has default margin and can be styled like any block.
Where it is used
- Every visible page
- Applying a page background or font
- Adding page wide classes for themes
Common mistakes
Using more than one body, or putting body before head.
| Attribute | Meaning |
|---|---|
onload | runs code when the page has loaded |
style, class, id | usual global attributes |
body. Browsers give it an 8 pixel margin by default.Everything people see on the page.
Quick quiz
1. Where does <meta> go?
Meta lives in head.
2. Which tag links a CSS file?
link rel="stylesheet".
3. <base> sets
Relative links use it.
Common questions
Where does <meta> go?
head. Meta lives in head.
Which tag links a CSS file?
<link>. link rel="stylesheet".