Thuta Learning
HTML
BasicWeb DevelopmentBeginner

Basic Structure

HTMLLesson 420 min

What you'll walk away with

  • Write the document skeleton (doctype, html, head, body) from memory
  • Know that a missing doctype triggers quirks mode and check it with document.compatMode
  • Choose a lang value that matches the content's language (my for Myanmar)
  • Explain what goes wrong without charset, viewport or title

Explain it simply

Explain it simply

Think of an HTML document as a letter in an envelope. The outside of the envelope carries information for the postal service, such as the address and the stamp, which nobody reads as part of the letter: that is the <head>. The sheet inside is the <body>, the content people actually read.

The <!DOCTYPE html> line at the very top is a label that tells the browser "this is a modern HTML document". The <html> element is the whole envelope, and its lang attribute says which language the letter is written in.

Problem → Why → Solution

The problem: fine on your laptop, broken on a phone

The page below has a heading and a paragraph but no doctype, no charset and no viewport. It can look fine on your laptop, yet on a phone the whole page appears shrunk, with tiny text you have to zoom to read. If the server does not state the encoding either, the browser has to guess, and a wrong guess turns the Myanmar text into unreadable symbols. Without the doctype, CSS also runs under the old rules of quirks mode.

cafe.html
<html>
<title>Mingalaba Cafe</title>
<h1>မင်္ဂလာ ကော်ဖီဆိုင်</h1>
<p>နေ့တိုင်း ဖွင့်ပါတယ်။</p>
</html>

Why does this happen?

The lines in the head are invisible on the page, so they seem optional, but they give the browser essential instructions. Without a viewport, phone browsers lay the page out at a desktop width (typically around 980px) and shrink it to fit the screen. The charset says how to decode the bytes, and the doctype switches on standards mode.

Core concept: each part of the skeleton

PartJobIf it is missing
<!DOCTYPE html>switches on standards modequirks mode: CSS behaves like very old browsers
<html lang="...">root element and the content's languagescreen readers and translation guess the language
<meta charset="UTF-8">how to decode bytes into charactersMyanmar text and emoji can break
<meta name="viewport">lay out at the phone's real widthpage shrunk, tiny text on phones
<title>name in tabs, bookmarks and search resultsthe tab shows the file name or URL

<!DOCTYPE html> is not a tag; it is a declaration that tells the browser to render by the modern standard. It must come first in the file and is not case-sensitive. Without it, the browser uses quirks mode and calculates things such as box sizes and font sizes inside tables the way browsers did many years ago. Older tutorials sometimes show a long doctype that mentions HTML 4.01 or XHTML and a DTD URL; for new pages, this short form is all you need.

The <head> holds information about the page, called metadata. Put <meta charset="UTF-8"> first in the head, because the standard requires it within the first 1024 bytes of the file. The viewport meta tells phone browsers to lay out at the screen's real width. The <title> should be a specific name for each page. Later, the <link> for a CSS file and a meta description for search results will join them in the head.

The <body> contains all the visible content. The lang attribute goes on <html> and states the language of the whole page: en for English, my for Myanmar. If one part of the page is in another language, add lang to that element as well. The order of elements in the body is the reading order for everyone, including screen reader users, so write the content in a sensible order.

Mental model: four layers of the skeleton
  1. Doctype: use standards mode
  2. html lang: which language
  3. head: information about the page
  4. body: what people see

The head is for browsers and tools; the body is for people.

General pattern: the document skeleton

html
<!DOCTYPE html>
<html lang="language-code">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Specific page title</title>
</head>
<body>
  visible content goes here
</body>
</html>

Replace language-code with a code such as en or my. The order inside head (charset first, then viewport, then title) works for every project.

Example: a complete first document

This document has every part. Notice that the English version uses lang="en" while the Myanmar version of this lesson uses lang="my": the value must match the language of the content.

html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>My First Page</title>
</head>
<body>
  <h1>My First Heading</h1>
  <p>My first paragraph.</p>
</body>
</html>

Code breakdown

  1. Line 1<!DOCTYPE html>

    Switches on standards mode. Type document.compatMode in the DevTools Console and you get "CSS1Compat"; without the doctype you get "BackCompat" (quirks mode).

  2. Line 4<meta charset="UTF-8">

    Tells the browser to decode the file as UTF-8, which handles Myanmar, English and emoji alike. Your editor must save the file as UTF-8 too.

  3. Line 5<meta name="viewport" content="width=device-width, initial-scale=1.0">

    width=device-width makes the layout width equal the phone's screen width, and initial-scale=1.0 opens the page without zoom.

  4. Line 6<title>My First Page</title>

    Shown on the tab rather than the page, and used as the name when someone bookmarks it.

  5. Lines 8-11<body>

    Only the h1 and p inside the body are visible on the page. </body> and </html> close the document.

You should see
The browser tab reads "My First Page". The page shows the large heading "My First Heading" with the paragraph "My first paragraph." below it. On a phone the text appears at a normal, readable size instead of shrunk.

Check it yourself

1. Check the mode

Press F12, open the Console, type document.compatMode and press Enter. "CSS1Compat" means standards mode.

2. Simulate a phone screen

With DevTools open, press Ctrl+Shift+M (Cmd+Shift+M on a Mac) to open the device toolbar. Delete the viewport meta for a moment and refresh to see how small the text becomes.

3. See the tags the browser adds

Remove the <head> and <body> tags and look at the Elements panel. The browser adds them back automatically, but writing them yourself is clearer and safer.

In real projects

How this is used in real projects

In real projects you do not type this skeleton into every file: a template or a framework's root layout produces it once. In a Next.js project, for example, <html lang> is set in the root layout and every page is wrapped by it. That also means a wrong lang or viewport in that one template is wrong across the whole site.

The title is one of the most-seen pieces of text a user meets: on crowded tab bars, in bookmarks and as the link in search results. That is why sites give each page its own title, such as "Menu - Mingalaba Cafe". Bilingual Myanmar and English sites serve each locale's pages with their own lang, so screen readers pick the right voice and browsers offer translation from the right language.

Common mistakes

Common mistakes

1. Using one title for every page

Copy a template and leave <title>Home</title> on every page, and a user with five tabs open cannot tell them apart, while search results show identical link text. Give each page a specific title.

2. Getting lang wrong

Reuse an English template for Myanmar content without changing lang="en" and a screen reader tries to read Myanmar text with an English voice. The code for Myanmar is my, not mm: MM is Myanmar's country code, not a language code.

3. Putting the charset too late

Placing <meta charset> after the title and long comments can push it beyond the first 1024 bytes of the file, by which point the browser may already have guessed the encoding. Always make it the first line inside the head.

Mini challenge

Mini challenge: a Myanmar-language page

Write a Myanmar-language page with the full skeleton for a tea house, and add one English sentence marked with its own lang.

  • Include a doctype so that document.compatMode is "CSS1Compat"
  • Give <html> the correct lang for Myanmar
  • Put charset (first), viewport and a title with the shop's name in the head
  • In the body, add a Myanmar heading, a Myanmar paragraph and an English paragraph with lang="en"
tea-house.html
<!-- TODO: the doctype that switches on standards mode -->
<!-- TODO: open html with the language code for Myanmar -->
<head>
  <!-- TODO: UTF-8 encoding, as the first thing in head -->
  <!-- TODO: viewport for phones -->
  <!-- TODO: a title with the shop name -->
</head>
<body>
  <!-- TODO: h1 with the shop name in Myanmar -->
  <!-- TODO: a Myanmar paragraph with the opening hours -->
  <!-- TODO: the same hours in English, marked with its own lang -->
</body>
<!-- TODO: close html -->

Expected: The tab shows the shop's name, and the page shows a Myanmar heading, a Myanmar paragraph and an English paragraph, all rendered correctly. document.compatMode in the Console returns "CSS1Compat".

Show hint

lang takes an ISO language code, which for Myanmar is my. Adding lang="en" to the English sentence's <p> overrides the language for that element only.

Show solution
tea-house.html
<!DOCTYPE html>
<html lang="my">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>ရွှေပြည် လက်ဖက်ရည်ဆိုင်</title>
</head>
<body>
  <h1>ရွှေပြည် လက်ဖက်ရည်ဆိုင်</h1>
  <p>မနက် ၆ နာရီကနေ ညနေ ၆ နာရီအထိ နေ့တိုင်း ဖွင့်ပါတယ်။</p>
  <p lang="en">Open every day from 6:00 to 18:00.</p>
</body>
</html>

Quick quiz 1 / 3

On a page without <!DOCTYPE html>, what does document.compatMode return?

Quick quiz 2 / 3

Where does the text of <title>Menu - Mingalaba Cafe</title> appear?

Quick quiz 3 / 3

Which lang value should <html> have for a page written in Myanmar?

What to remember

  • <!DOCTYPE html> switches on standards mode; without it you get quirks mode.
  • <html lang> states the content's language: en for English, my for Myanmar.
  • The head holds the charset (first), the viewport and a page-specific title.
  • Only the content inside the body is visible on the page.

HTML Living Standard — HTML Syntax — WHATWG

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.

Basic Structure | Thuta Learning