Skip to content

Beginner · HTML basics · topic 5 of 64 · 25 min

Page structure: the skeleton of every page

Explanation

Every HTML page has the same skeleton: a doctype, an html element with a language, a head with information about the page, and a body with the content people see. Elements sit inside each other like boxes, and attributes add extra details to a tag.

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.

html
<!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>
The full skeleton of a small shop page
LineWhat 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.
Think of it like this: Think of a letter in an envelope. The head is the envelope: the address and the stamp, which the post office reads but which is not the letter itself. The body is the letter inside that the person actually reads. The doctype is like printing "Inland Letter" on top, so everyone knows the format.

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.

html
<!-- 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>
Close the inner tag first

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.

Careful: Comments are not secret. Anyone can read them with View Source. Never put passwords, keys or private notes in HTML comments.
Tip: In VS Code, type ! and press Tab in an empty .html file to get the whole skeleton, then press Shift+Alt+F to fix the indentation.

Watch the lesson

Page structure: the skeleton of every page · 1/6

The HTML skeleton

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)

Task 1 · Code · HTML

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.

Task 2 · Code · HTML

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>.

Task 3 · Practice

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

Question 1

1.Which part of the page holds the content the visitor sees?

Question 2

2.What does <meta name="viewport" content="width=device-width, initial-scale=1"> do?

Question 3

3.Which of these is a void element (it has no closing tag)?

Question 4

4.Which nesting is correct?

Question 5

5.Why should you use <meta charset="utf-8">?

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.

← Previous: Browser DevTools: look inside any page