HTML · The document layer
What is the structure of a valid HTML document?
Short answer
A document starts with the doctype, then a single html element containing a head for metadata and a body for rendered content. The head loads the title, charset, viewport and styles before the body paints.
The doctype tells the browser to use standards mode rather than quirks mode. After that, the html element is the root, and it should carry a lang attribute so assistive technology knows the document language.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Vocal Hire</title>
</head>
<body>
<main>
<h1>Interview practice</h1>
</main>
</body>
</html>What goes where
- The head holds machine-readable metadata and resource links, not visible page content
- The body holds everything the user can see or interact with
- charset should appear early so the parser decodes text correctly
- The title is required in practice and is used in tabs, history and search results
- Only one html, head and body element should exist per document
The browser can recover from missing tags, but you should still write a complete skeleton. It makes the document predictable and avoids quirks-mode layout differences.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What does the doctype actually do?
- 2Why is the lang attribute important?
- 3Can a document have more than one head or body?
- 4Why should charset come early in the head?
Say it in the interview
A valid document starts with the HTML5 doctype so the browser uses standards mode. Then there is one html root with a lang attribute. The head holds metadata such as charset, viewport, title and styles, and the body holds the visible content. Browsers can recover from missing tags, but writing the full skeleton keeps parsing predictable and avoids quirks mode.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live HTML mock interview and get scored feedback on depth, clarity and confidence.