Reading HTML structure
You'll learn to read the shape of an HTML file, tags inside tags.
Watch & read
Start with the required ones. The others are there when you need them.
Explanation
You want to make a page. The browser needs to know which text is a heading, which is a paragraph, and where a picture goes. HTML is how you tell it.
Think of a tiffin carrier. The big carrier holds boxes. Each box holds food. Nothing hangs half outside. HTML works the same way: boxes inside boxes, and every box is closed before its outer box closes.
Each box is an element. You open it with a tag like <p> and close it with </p>. The closing tag
has a /. The text between them is what the element holds.
<body><h1>Nusrat's notes</h1><p>I study <strong>CSE</strong> at DU.</p></body>
Here body holds an h1 and a p. The p holds some text and a strong. Putting one element inside
another is called nesting.
Some tags carry extra information, called attributes. They go inside the opening tag:
<a href="https://github.com">. Here href is the attribute name and the address is its value.
Every page has two main parts inside <html>:
<head>holds facts about the page: its title in the tab, links to CSS. You do not see it on the page.<body>holds everything you see.
People often close tags in the wrong order, like <p><strong>CSE</p></strong>. That is a box closed
from outside its outer box. The browser tries to guess what you meant, and often guesses badly. Close the
inner one first: </strong></p>.
When you read HTML, use the indentation. Each step to the right means "inside the line above". To find where an element ends, look straight down for the closing tag at the same indent.
Code tour
Click a line number with a ring to read the note for that line.
Quick check
3 questions. Each one explains itself after you answer.
- 1 / 3Which line is nested correctly?
- 2 / 3Where does text you want people to see on the page go?
- 3 / 3In
<img src="cat.jpg" alt="A sleeping cat">, what issrc?