Beginner · HTML basics · topic 5 of 64 · 25 min
Page structure: the skeleton of every page
Explanation
The skeleton
Every HTML page follows the same outline. Browsers try to guess when a part is missing, but guessing leads to strange bugs. Write the full skeleton every time. With Emmet in VS Code it takes ten seconds.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Sharma Kirana Store | Home</title>
</head>
<body>
<!-- Main content starts here -->
<h1>Sharma Kirana Store</h1>
<p>Fresh groceries, open 7 am to 10 pm.</p>
</body>
</html>| Line | What it does |
|---|---|
| <!doctype html> | Tells the browser this is modern HTML. Without it, browsers fall back to an old "quirks mode" with odd layout rules. |
| <html lang="en"> | The root element that holds everything. lang names the language (hi for Hindi, ta for Tamil) for screen readers and translators. |
| <head> | Information about the page. It is not shown inside the page itself. |
| <meta charset="utf-8"> | The character set. UTF-8 can show every script: Hindi, Tamil, Bengali, the rupee sign and emoji. |
| <meta name="viewport" ...> | Makes the page fit a phone screen instead of showing a tiny zoomed-out desktop page. |
| <title> | The text in the browser tab, in bookmarks and in search results. |
| <body> | Everything the visitor sees on the page. |
Nesting and indentation
Elements go inside other elements. This is called nesting. The outer element is the parent and the inner ones are its children. A child must close before its parent closes, so the tags never cross each other.
<!-- Right: strong closes before p closes -->
<p>We are open <strong>every day</strong>.</p>
<!-- Wrong: the tags cross each other -->
<p>We are open <strong>every day.</p></strong>Indentation means adding spaces at the start of a line to show how deep an element sits. The browser ignores these spaces, but people reading your code need them. Use 2 spaces for each level and let your editor tidy the file.
Attributes
An attribute is extra information written inside the opening tag, as name="value". Examples are lang="en", href="about.html" and id="contact". Always put the value in double quotes. Some attributes are boolean (on or off): just writing the name turns them on, as in <video controls>.
Void elements and comments
A few elements can never hold content, so they have no closing tag. They are called void elements: <meta>, <link>, <img>, <br>, <hr> and <input>. Write them as <img src="logo.png" alt="Shop logo">. A slash at the end (<br />) is allowed but not needed.
A comment is a note for developers that the browser does not show. It starts with <!-- and ends with -->. Use comments to label big sections or to explain something unusual.
Watch the lesson
Page structure: the skeleton of every page · 1/6
Every web page in the world starts with the same skeleton. Let us learn it once and use it forever.
Prefer a video by a teacher? Find free videos on “html page structure doctype head body tutorial for beginners” on YouTube ↗
In real life: A scholarship form in three languages
A state scholarship portal has Hindi, Marathi and English versions. Each version sets the right lang value (hi, mr or en), so screen readers pronounce the words correctly, and meta charset="utf-8" makes the Devanagari letters show properly instead of empty boxes. The viewport tag makes the form fit a low-cost phone, and a clear title such as "Scholarship form - Step 2 of 4" tells students where they are, even with many tabs open.
Practice (0/3 done)
Complete this page skeleton for a kirana shop. Add lang="en" to the <html> tag. Inside the head, add <meta charset="utf-8">, the viewport tag <meta name="viewport" content="width=device-width, initial-scale=1"> and a <title> with the shop name.
Practise attributes, comments and void elements. In the body: add an HTML comment that says Shop timings. Below it, give the paragraph the attributes id="timings" and class="note". After the paragraph, add a horizontal line with the void element <hr>.
On a laptop, open any two websites (for example a news site and a government site). Press Ctrl+U to view the page source. Find the doctype, the lang value, the charset, the viewport tag and the title.
Quick quiz
Read more (free)
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.