Read the page from the outside in
The example below is a complete document. Save it as index.html and open it in a browser. You will see the main heading, a short introduction, a second heading and an MDN link. The tab shows “Student coding notes”. The doctype and metadata do not appear as visible paragraphs, but they influence how the browser interprets the page.
Start with the outside pair, <html> and </html>, then look at its two children: head for document information and body for page content. Inside body, main groups the central content. Reading the tree this way helps you spot elements placed in the wrong parent.
DOCTYPE and standards mode
<!doctype html> is a declaration at the top of the file, not an element with a closing tag. In modern documents it tells the browser to use standards mode instead of older compatibility behaviour known as quirks mode. Capitalisation is not significant here; the example uses the common lowercase spelling.
Leaving it out may change layout behaviour even when your headings still appear. Keep it at the very start of a normal HTML document. It is not an instruction to install HTML or choose a numbered HTML release.
The html element and page language
<html lang="en"> begins the root element, and </html> closes it. Everything else in this document belongs inside that root. The lang attribute identifies the human language of the page’s content as English; use a different valid language tag for a page written in another language.
The opening tag is <html lang="en">, the closing tag is </html>, and the material between them is the element’s content. lang="en" is an attribute: a name and quoted value on the opening tag. Attributes configure or describe an element; they are not separate visible text.
The head contains information about the document
<head> holds metadata, not the article people read. <meta charset="UTF-8"> declares the character encoding so letters and symbols are decoded correctly. Put a character-encoding declaration near the start of head. The meta element is void: it has one tag and cannot wrap content, so do not add </meta>.
<meta name="viewport" content="width=device-width, initial-scale=1"> tells mobile browsers to use the device width for the layout viewport and start at a normal scale. It does not make an oversized layout responsive by itself; CSS and flexible layouts still matter. <title>Student coding notes</title> names the document in the browser tab and often in bookmarks or search results. The title is different from the visible h1 heading.
The body contains page content
<body> wraps content that appears in the webpage. <main> identifies its primary content. <h1> is the page’s main heading; <h2> starts a section under it. <p> marks each paragraph. <a href="…"> creates a link: href gives the destination and the words between <a> and </a> are the link text people can read and activate.
A browser gives these elements default appearance, but their main value is meaning and structure. A person can follow the MDN link without JavaScript. Headings and a main region also help people using assistive technology navigate the page.
Nesting, closing tags and indentation
Most elements have an opening tag, content and a closing tag. Nested tags must close in reverse order: <p>Read <strong>carefully</strong>.</p> is valid nesting; closing p before strong would overlap the elements. By contrast, void elements such as meta and img have no closing tag and cannot contain child text or elements.
Indent each child level consistently, as in the example. Indentation helps humans see that head and body are inside html and that the headings are inside main; for ordinary text, extra spaces and line breaks in source do not produce matching visual indentation. The browser may repair badly nested markup, but the result can differ from what you meant.
Common mistakes include putting a visible heading in head, treating title as the on-page heading, forgetting a closing tag, writing </meta>, and leaving lang or viewport metadata out. Inspect the browser’s DOM and use an HTML checker when the output surprises you. Next, try changing the headings and link, then move on to CSS and JavaScript.
Syntax
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Student coding notes</title>
</head>
<body>
<main>
<h1>Student coding notes</h1>
<p>Small explanations make new ideas easier to revisit.</p>
<h2>Start with the basics</h2>
<p>Read the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML">HTML reference on MDN</a>.</p>
</main>
</body>
</html>Examples
A complete student notes page
Save as index.html or choose Edit in Playground. The browser tab shows the title; the body shows the headings, paragraphs and link.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Student coding notes</title>
</head>
<body>
<main>
<h1>Student coding notes</h1>
<p>Small explanations make new ideas easier to revisit.</p>
<h2>Start with the basics</h2>
<p>Read the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML">HTML reference on MDN</a>.</p>
</main>
</body>
</html>- The doctype requests standards mode, then html encloses head and body. Indentation mirrors that parent-child relationship.
- lang, charset and viewport describe how to interpret the page. The two meta tags are void elements with attributes, not paired containers.
- The title belongs to head and labels the browser tab. The visible h1 and h2 belong to body and form a reading hierarchy.
- The anchor’s href points to MDN; its text describes that destination. Changing the link text does not change the destination.
- Replace the paragraph or heading, save and refresh. If the change is missing, check that you opened the file you edited.
Best practices
- Include a doctype, document language, encoding, viewport and meaningful title.
- Keep visible content in body and metadata in head.
- Close non-void elements in reverse nesting order and indent consistently.
Browser compatibility
Support applies to the named feature, not every attribute or behaviour in this article. Versions refer to browsers, not operating systems.
These records cover the example's elements and metadata attributes. DOCTYPE controls document mode and is explained separately; no whole-document support claim is inferred.
<html>
Desktop
- Chrome
- Supported
From 1 - Firefox
- Supported
From 1 - Safari
- Supported
From 1 - Edge
- Supported
From 12 - Opera
- Supported
By 12.1 (possibly earlier)
Mobile
- Safari on iOS
- Supported
From 1 - Chrome for Android
- Supported
From 18 - Firefox for Android
- Supported
From 4 - Samsung Internet
- Supported
From 1.0
MDN BCD record for this feature · MDN reference
Support history and limitations
Chrome
- From 1
Firefox
- From 1
Safari
- From 1
Edge
- From 12
Opera
- By 12.1 (possibly earlier)
Safari on iOS
- From 1
Chrome for Android
- From 18
Firefox for Android
- From 4
Samsung Internet
- From 1.0
<head>
Desktop
- Chrome
- Supported
From 1 - Firefox
- Supported
From 1 - Safari
- Supported
From 1 - Edge
- Supported
From 12 - Opera
- Supported
From 15
Mobile
- Safari on iOS
- Supported
From 1 - Chrome for Android
- Supported
From 18 - Firefox for Android
- Supported
From 4 - Samsung Internet
- Supported
From 1.0
MDN BCD record for this feature · MDN reference
Support history and limitations
Chrome
- From 1
Firefox
- From 1
Safari
- From 1
Edge
- From 12
Opera
- From 15
Safari on iOS
- From 1
Chrome for Android
- From 18
Firefox for Android
- From 4
Samsung Internet
- From 1.0
<meta> charset
Desktop
- Chrome
- Supported
From 1 - Firefox
- Supported
From 1 - Safari
- Supported
From 3 - Edge
- Supported
From 12 - Opera
- Supported
From 15
Mobile
- Safari on iOS
- Supported
From 2 - Chrome for Android
- Supported
From 18 - Firefox for Android
- Supported
From 4 - Samsung Internet
- Supported
From 1.0
MDN BCD record for this feature
Support history and limitations
Chrome
- From 1
Firefox
- From 1
Safari
- From 3
Edge
- From 12
Opera
- From 15
Safari on iOS
- From 2
Chrome for Android
- From 18
Firefox for Android
- From 4
Samsung Internet
- From 1.0
<meta> name · viewport
Desktop
- Chrome
- Not supported
- Firefox
- Not supported
- Safari
- Not supported
- Edge
- Not supported
- Opera
- Not supported
Mobile
- Safari on iOS
- Supported
From 3 - Chrome for Android
- Supported
From 18 - Firefox for Android
- Supported
From 4 - Samsung Internet
- Supported
From 1.0
MDN BCD record for this feature · MDN reference
Support history and limitations
Chrome
- Not supported
Firefox
- Not supported
Safari
- Not supported
Edge
- Not supported
Opera
- Not supported
Safari on iOS
- From 3
Chrome for Android
- From 18
Firefox for Android
- From 4
Samsung Internet
- From 1.0
<title>
Desktop
- Chrome
- Supported
From 1 - Firefox
- Supported
From 1 - Safari
- Supported
From 1 - Edge
- Supported
From 12 - Opera
- Supported
From 15
Mobile
- Safari on iOS
- Supported
From 1 - Chrome for Android
- Supported
From 18 - Firefox for Android
- Supported
From 4 - Samsung Internet
- Supported
From 1.0
MDN BCD record for this feature · MDN reference
Support history and limitations
Chrome
- From 1
Firefox
- From 1
Safari
- From 1
Edge
- From 12
Opera
- From 15
Safari on iOS
- From 1
Chrome for Android
- From 18
Firefox for Android
- From 4
Samsung Internet
- From 1.0
<body>
Desktop
- Chrome
- Supported
From 1 - Firefox
- Supported
From 1 - Safari
- Supported
From 1 - Edge
- Supported
From 12 - Opera
- Supported
From 15
Mobile
- Safari on iOS
- Supported
From 1 - Chrome for Android
- Supported
From 18 - Firefox for Android
- Supported
From 4 - Samsung Internet
- Supported
From 1.0
MDN BCD record for this feature · MDN reference
Support history and limitations
Chrome
- From 1
Firefox
- From 1
Safari
- From 1
Edge
- From 12
Opera
- From 15
Safari on iOS
- From 1
Chrome for Android
- From 18
Firefox for Android
- From 4
Samsung Internet
- From 1.0
<main>
Desktop
- Chrome
- Supported
From 26 - Firefox
- Supported
From 21 - Safari
- Supported
From 7 - Edge
- Supported
From 12 - Opera
- Supported
From 16
Mobile
- Safari on iOS
- Supported
From 7 - Chrome for Android
- Supported
From 26 - Firefox for Android
- Supported
From 21 - Samsung Internet
- Supported
From 1.5
MDN BCD record for this feature · MDN reference
Support history and limitations
Chrome
- From 26
Firefox
- From 21
Safari
- From 7
Edge
- From 12
Opera
- From 16
Safari on iOS
- From 7
Chrome for Android
- From 26
Firefox for Android
- From 21
Samsung Internet
- From 1.5
<h1>
Desktop
- Chrome
- Supported
From 1 - Firefox
- Supported
From 1 - Safari
- Supported
From 1 - Edge
- Supported
From 12 - Opera
- Supported
From 15
Mobile
- Safari on iOS
- Supported
From 1 - Chrome for Android
- Supported
From 18 - Firefox for Android
- Supported
From 4 - Samsung Internet
- Supported
From 1.0
MDN BCD record for this feature · MDN reference
Support history and limitations
Chrome
- From 1
Firefox
- From 1
Safari
- From 1
Edge
- From 12
Opera
- From 15
Safari on iOS
- From 1
Chrome for Android
- From 18
Firefox for Android
- From 4
Samsung Internet
- From 1.0
<h2>
Desktop
- Chrome
- Supported
From 1 - Firefox
- Supported
From 1 - Safari
- Supported
From 1 - Edge
- Supported
From 12 - Opera
- Supported
From 15
Mobile
- Safari on iOS
- Supported
From 1 - Chrome for Android
- Supported
From 18 - Firefox for Android
- Supported
From 4 - Samsung Internet
- Supported
From 1.0
MDN BCD record for this feature · MDN reference
Support history and limitations
Chrome
- From 1
Firefox
- From 1
Safari
- From 1
Edge
- From 12
Opera
- From 15
Safari on iOS
- From 1
Chrome for Android
- From 18
Firefox for Android
- From 4
Samsung Internet
- From 1.0
<p>
Desktop
- Chrome
- Supported
From 1 - Firefox
- Supported
From 1 - Safari
- Supported
From 1 - Edge
- Supported
From 12 - Opera
- Supported
From 15
Mobile
- Safari on iOS
- Supported
From 1 - Chrome for Android
- Supported
From 18 - Firefox for Android
- Supported
From 4 - Samsung Internet
- Supported
From 1.0
MDN BCD record for this feature · MDN reference
Support history and limitations
Chrome
- From 1
Firefox
- From 1
Safari
- From 1
Edge
- From 12
Opera
- From 15
Safari on iOS
- From 1
Chrome for Android
- From 18
Firefox for Android
- From 4
Samsung Internet
- From 1.0
<a> href
Desktop
- Chrome
- Supported
From 1 - Firefox
- Supported
From 1 - Safari
- Supported
From 1 - Edge
- Supported
From 12 - Opera
- Supported
From 15
Mobile
- Safari on iOS
- Supported
From 1 - Chrome for Android
- Supported
From 18 - Firefox for Android
- Supported
From 4 - Samsung Internet
- Supported
From 1.0
MDN BCD record for this feature
Support history and limitations
Chrome
- From 1
Firefox
- From 1
Safari
- From 1
Edge
- From 12
Opera
- From 15
Safari on iOS
- From 1
Chrome for Android
- From 18
Firefox for Android
- From 4
Samsung Internet
- From 1.0
MDN BCD 8.1.5 · Dataset built 2026-10-08 · Mapping reviewed 2026-10-21. These dates are not individual browser-test or claim-verification dates. Unknown means the data does not establish support.