How a Web Page Works: HTML Tags, Elements and Attributes
A web page is a text file full of labelled pieces. Learn tags, attributes and nesting with three tiny pages, and see what breaks when an attribute or a closing tag is wrong.
What you will learn
- Explain what the browser does with an .html file
- Name the four parts of an element: opening tag, attribute, content, closing tag
- Nest elements correctly and write the standard page skeleton
- Use headings, paragraphs, strong, em, img, lists and links
Before you start
- A browser and any text editor
Think of a courier with a parcel. The courier never opens it. They read the label, see what's inside and where it goes, and handle it the right way.
An HTML tag is that label. It tells the browser what a piece of the page is: a heading, a paragraph, a link. An attribute is an extra line on the label, such as where a link goes or which picture to show. So a web page is just a text file full of labelled pieces, and the browser reads the labels and draws the page.
What the browser does with your file
You write a plain text file called index.html in any editor. The browser reads it from top to bottom, tag by tag: h1 means a big heading, p means a paragraph. Then it draws the page. The tags themselves disappear and only the result is left.
You don't need a server or anything installed. Double-click the file and Chrome opens it.
The four parts of one element
Here is one link, taken apart:
The tag name sits inside angle brackets, and a means link. Inside the opening tag is an attribute, href="schedule.html", always written as name equals value. href is the address. Then comes the content, "course schedule", which is what you click. The closing tag </a> ends it.
Elements go inside other elements
Elements nest like boxes packed inside boxes. The rule is the one you'd follow with real boxes: the box you opened last, you close first.
<!-- good: strong closes before p closes -->
<p>A short course for <strong>complete beginners</strong>.</p>
<!-- wrong: the tags cross -->
<p>A short course for <strong>complete beginners.</p></strong>
Indent the inner tags by two spaces. The indentation then shows you the boxes at a glance.
Every page starts the same way
Here's the first example, the skeleton every page uses:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>About the course</title>
</head>
<body>
<h1>Web Basics</h1>
<p>A short course for complete beginners.</p>
</body>
</html>
Line 1 says this is a modern HTML page, and lang="en" on the html tag says it's in English. Everything else goes inside html.
The head holds facts about the page that are not drawn on it. The title goes to the browser tab, so the tab reads "About the course". The body is what you see: one h1 heading and one p paragraph.
Headings, paragraphs and emphasis
The second file adds a bit more text:
<h1>Web Basics</h1>
<p>A short course for <strong>complete beginners</strong>.</p>
<!-- a comment: the browser skips it -->
<h2>What you will build</h2>
<p>One small page, <em>written by hand</em>.</p>
h1 is the title of the page, one per page, and h2 starts each section under it. Inside a paragraph, strong means important and shows in bold, and em means stressed and shows in italics. The comment between the two parts is a note for you; the browser skips it. The same file also uses <br>, an empty element with no closing tag that just breaks the line.
Images, lists and links
The third file has the pieces you'll use on almost every page:
<body>
<img src="course-logo.svg" alt="Web Basics logo" width="80">
<h1>Web Basics</h1>
<h2>What you will learn</h2>
<ul>
<li>Tags and attributes</li>
<li>Links and images</li>
</ul>
<h2>How to join</h2>
<ol>
<li>Install a code editor</li>
<li>Read the <a href="schedule.html">course schedule</a></li>
</ol>
</body>
img is another empty element. src says which file to show, and alt gives the words for anyone who can't see the picture. ul is a bulleted list and each item is an li. If you want numbers, use ol instead, as the "How to join" steps do. And the link is our a again: the href is the address, the content is what you click.
Change one attribute, change the result
Click "course schedule" and the href takes the browser to schedule.html, a second page in the same folder.
Now break it. Change src="course-logo.svg" to src="logo.svg", a file that doesn't exist. There's no picture any more, and the browser shows the alt text, "Web Basics logo", in its place. The tag says what a piece is; its attributes say which file and which address.
One missing closing tag
In the second file, </strong> ends the bold, so only "complete beginners" is bold. Delete that closing tag and everything after it turns bold.
The browser shows no error message. It just guesses. So close every tag you open. Most editors type the closing tag for you as soon as you finish the opening one, which helps a lot.
Common mistakes
- Crossed tags. Closing an outer box before the inner one. Close the inner tag first.
- A missing closing tag. The style or meaning runs on into the rest of the page, silently.
- A wrong file name in
srcorhref. The image falls back to its alt text and the link leads nowhere. Check the spelling against the folder. - No
alton an image. Screen readers then have nothing to read out.
Quick recap
| Word | What it does | Example |
|---|---|---|
| Tag | says what the piece is | <h1>, <p>, <a> |
| Attribute | says where or which, as name="value" | href="schedule.html", alt="..." |
| Element | opening tag + content + closing tag | <a href="...">course schedule</a> |
| Nesting | close the inner box first | <p><strong>..</strong></p> |
Try it yourself
Make an about.html page with your name as the h1, two h2 sections, a paragraph with one strong word, a list of three hobbies, an image with alt text, and a link to a second page. Then give the page some real structure with the tags in semantic HTML and landmarks.
Related course on Udemy
The Python Architect Masterclass: Full Stack to AI Engineer
Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)Related posts
One Request, Two Answers: the Same Post as an HTML Page and as JSON
Ask a Django blog for the same post twice: once as a 12,731-byte HTML page built by a template, once as 2,976 bytes of JSON built by a serializer. Compare the headers, see who builds the page, and why the server still owns every write.
A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx
Make a blog design from a prompt in Figma Make, download src.zip, unzip it with Python's zipfile module, and read the two files that matter: App.tsx with its selectedPost state and BlogCard.tsx with its props.
Semantic HTML: header, nav, main, aside and footer as Page Landmarks
The same page written as div soup and with semantic tags looks identical, but only one gives screen readers and search engines landmarks and an outline. Plus tables, div, span and the one-main rule.
HTML Forms: Labels, Names, Input Types and Where the Data Goes (GET vs POST)
Follow a sign-up form's answers out of the page: label and id, name as the key, browser validation, the query string a GET form builds, and why POST hides it. Plus the most common bug, an input with no name.
