In this lesson you will learn about the basic structure of an HTML document. Every HTML page follows the same skeleton — once you understand it, everything else becomes easy.
Below is a complete, minimal HTML page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My First HTML Page</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>Welcome to my first HTML page.</p>
</body>
</html>
The <!DOCTYPE html> declaration must be the very first line of every HTML document.
<!DOCTYPE html> and <!doctype html> are both valid<!DOCTYPE html>
The <html> element is the root of every HTML page. All other elements must be inside it.
lang attribute declares the language of the page (e.g. lang="en" for English)<html lang="en">
...
</html>
The <head> element contains meta-information about the page — things that are not visible on the page itself.
| Tag | Purpose |
|---|---|
<title> |
Sets the tab/window title shown in the browser |
<meta charset="UTF-8"> |
Sets character encoding to support all languages |
<meta name="description"> |
Describes the page for search engines |
<link> |
Links external CSS stylesheets |
<script> |
Links or embeds JavaScript |
The <body> element contains everything that is visible on the page:
<h1> to <h6><p><img><a><table><ul>, <ol>HTML has six levels of headings — <h1> is the largest and <h6> is the smallest:
<h1>Heading 1 — Largest</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6 — Smallest</h6>
<h1> per page. It represents the main topic of the page and is important for SEO.
A paragraph is defined with the <p> tag:
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
Browsers automatically add some spacing before and after each paragraph.
Links are defined with the <a> tag. The destination URL is set using the href attribute:
<a href="https://www.example.com">Visit Example</a>
The href stands for Hypertext REFerence — it specifies where the link goes.
Images are embedded using the <img> tag. It is a self-closing tag (no end tag needed):
<img src="image.jpg" alt="Description of image">
| Attribute | Purpose |
|---|---|
src |
Specifies the path/URL of the image |
alt |
Alternative text shown if image fails to load (also used by screen readers) |
width |
Sets the width of the image |
height |
Sets the height of the image |
You can view the raw HTML code of any webpage: