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.

The root has two childrenhead(info)body(visible)html
The root has two children

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.

AttributeMeaning
langlanguage of the page (en, hi, fr)
dirtext direction (ltr, rtl)
Tip:Always set lang. Screen readers pick the right voice from it and search engines use it to understand the page.
Example: <html>Try it Yourself

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.

What lives in the headtitlemetalinkstyle /scripthead
What lives in the head

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.

Tip:If you put a visible element (like a paragraph) in the head, the browser closes the head early and moves on to the body.
Example: <head>Try it Yourself

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.

Where the title shows<title>Browser tabBookmarksGoogle result
Where the title shows

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.

Tip:A page can have only one title. Write plain text only; tags inside a title are not allowed.
Example: <title>Try it Yourself

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.

Common meta tagscharset: how to read the lettersviewport: mobile widthdescription: text in search resultsog:image: picture in shared links
Common meta tags

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.

AttributeMeaning
charsetcharacter encoding (UTF-8)
namekind of information (description, viewport, robots)
contentthe value
http-equivacts like an HTTP header
propertyused by Open Graph (og:title)
Tip:Every page needs meta charset and meta viewport. Without the viewport tag mobile pages look tiny.
Example: <meta>Try it Yourself

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.

link rel="stylesheet"<link href=style.css>Browser downloadsthe CSSRules matchedto elementsStyled page
link rel="stylesheet"

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.

AttributeMeaning
relstylesheet, icon, canonical, preload, alternate
hrefaddress of the file
typefile type
mediawhen the file applies
hreflanglanguage of the target
askind of file for preload
Tip:link is not the same as a. A link element is not clickable; it only connects resources.
Example: <link>Try it Yourself

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.

<style> is a hidden metadata. It goes inside: head (or body in practice). It can contain: CSS text.<style ...>content(CSS text)</style>
<style> is a hidden metadata. It goes inside: head (or body in practice). It can contain: CSS text.

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.

AttributeMeaning
mediaapplies the rules only on matching screens
typealways text/css (can be left out)
Tip:Rules in a style element are overridden by an inline style attribute on an element.
Example: <style>Try it Yourself

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.

<base> is a void (no end tag). It goes inside: head. It can contain: nothing.<base ...>no contentno end tag
<base> is a void (no end tag). It goes inside: head. It can contain: nothing.

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.

AttributeMeaning
hrefthe base address
targetdefault target for links (_blank, _self)
Tip:A wrong base breaks every relative link and image on the page, so use it with care.
Example: <base>Try it Yourself

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.

Loading a scriptHTML parseddefer scriptdownloadsHTML finishedScript runs
Loading a script

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.

AttributeMeaning
srcaddress of a script file
deferrun after the page is built
asyncrun as soon as it downloads
typemodule or application/ld+json
integritysecurity hash
Tip:Without defer or async a script in the head stops the page from showing until it has run.
Example: <script>Try it Yourself

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.

<noscript> is a fallback. It goes inside: head or body. It can contain: message, link, style.<noscript ...>content(message, link, style)</noscript>
<noscript> is a fallback. It goes inside: head or body. It can contain: message, link, style.

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.

Tip:Keep the message short and helpful, for example: Please turn on JavaScript to use this tool.
Example: <noscript>Try it Yourself

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.

The body holds the whole visible pageheadermainfooterbody
The body holds the whole visible page

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.

AttributeMeaning
onloadruns code when the page has loaded
style, class, idusual global attributes
Tip:Most layout work happens inside body. Browsers give it an 8 pixel margin by default.
Example: <body>Try it Yourself

Everything people see on the page.

Quick quiz

1. Where does <meta> go?

2. Which tag links a CSS file?

3. <base> sets

Common questions

Where does <meta> go?

head. Meta lives in head.

Which tag links a CSS file?

<link>. link rel="stylesheet".

My notes
Ask a question about this lesson