HTML (HyperText Markup Language) is the standard language used to create webpages.
HTML tells the browser:
Every website you visit uses HTML.
Every HTML document follows a standard structure.
<!DOCTYPE html>
<html>
<head>
<title>My First Page</title>
</head>
<body>
<h1>Hello World</h1>
<p>Welcome to HTML.</p>
</body>
</html>
Notice that this document contains several parts.
HTML Document
│
├── DOCTYPE
├── html
│ ├── head
│ └── body
We will look at each of these individually.
At the top of every HTML document is the DOCTYPE declaration.
<!DOCTYPE html>
This tells the browser that the document uses HTML5.
Without this line, browsers may render pages differently.
For this reason, the DOCTYPE should always be the first line of an HTML document.
<!DOCTYPE html>
<html>
...
</html>
The <html> element is the root element of every webpage.
Everything on the page lives inside this tag.
<html>
<head>
</head>
<body>
</body>
</html>
Often, we also specify a language.
<html lang="en">
This tells browsers and search engines that the page is written in English.
It also helps screen readers and accessibility tools.
The <head> element contains information about the webpage.
Most of this information is not displayed directly to users.
<head>
<title>My Website</title>
<meta charset="UTF-8">
</head>
<head>head
├── title
├── meta
├── link
├── script
└── style
| Element | Purpose |
|---|---|
title |
Sets the browser tab title |
meta |
Provides information about the page |
link |
Connects external files such as CSS |
script |
Loads JavaScript |
style |
Contains CSS |
The <body> element contains everything visible on the webpage.
<body>
<h1>Welcome</h1>
<p>This is my website.</p>
</body>
Everything users see is placed inside the <body> element.
body
├── Headings
├── Paragraphs
├── Images
├── Forms
└── Buttons
Meta tags provide information about a webpage.
They help browsers and search engines understand the page.
One common meta tag is:
<meta charset="UTF-8">
This enables support for many characters and languages.
<p>नेपाल 🇳🇵</p>
Another common meta tag is:
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
>
This tells mobile devices how to display the page.
Without it, webpages may appear zoomed out on phones.
With it, webpages become responsive.
We can also provide a description for the webpage.
<meta
name="description"
content="Learn HTML from beginner to advanced."
>
Search engines may display this description in search results.
HTML is built using tags.
<h1>Hello</h1>
Notice the structure:
<h1> Opening Tag
Hello Content
</h1> Closing Tag
Most HTML elements follow this pattern.
Attributes provide additional information about an element.
<a href="https://google.com">
Google
</a>
Here:
href → Attribute
https://google.com → Value
Attributes are placed inside the opening tag.
<tag attribute="value">
An element can have multiple attributes.
<img
src="image.jpg"
alt="Nature"
width="300"
>
Comments are notes written for developers.
Browsers completely ignore comments.
<!-- This is a comment -->
<!-- Navigation Section -->
<nav>
...
</nav>
HTML tags are case-insensitive.
The following examples work the same way:
<h1>Hello</h1>
<H1>Hello</H1>
<H1>HELLO</H1>
However, modern HTML follows the best practice of using lowercase tags.
<h1>Hello</h1>
Browsers ignore extra spaces and line breaks.
<p>Hello World</p>
Hello World
Even if the content appears on multiple lines:
<p>
Hello
World
</p>
Hello World
The browser automatically collapses multiple spaces and line breaks into a single space.
<pre> ElementSometimes we want spaces and line breaks to be preserved exactly as they are written.
For this purpose, HTML provides the <pre> (preformatted text) element.
<pre>
Hello
World
</pre>
Hello
World
Notice that all spaces and line breaks remain unchanged.
<pre>The <pre> element is commonly used for:
Some characters have special meaning in HTML.
For example:
<p><h1></p>
The browser interprets <h1> as an HTML tag.
If we want to display it as plain text, we use HTML entities.
<p><h1></p>
<h1>
| Character | Entity |
|---|---|
< |
< |
> |
> |
& |
& |
" |
" |
' |
' |
| Space | |
| © | © |
| ® | ® |
| ™ | ™ |
<p>© 2025 Samir</p>
© 2025 Samir
)The entity creates a space that the browser does not collapse.
HTML CSS
HTML CSS
Every HTML page starts with a similar foundation.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Page Title</title>
</head>
<body>
Content Goes Here
</body>
</html>
As you continue learning HTML, everything you build will be placed inside this structure.
This structure forms the foundation of every website on the Internet.