HTML Basic Structure
Every HTML document follows a standard skeleton: a doctype declaration, an <html> root element, a <head> for metadata, and a <body> for visible content.
The doctype tells the browser which HTML version to use. Without it, browsers may render pages in 'quirks mode', causing inconsistent styling.
<!DOCTYPE html>
<html>
<head>...</head>
<body>...</body>
</html>The doctype
<!DOCTYPE html> must be the very first line. It declares the document as HTML5, the current standard.
html, head, body
<html> wraps the whole document. <head> holds metadata like the title and links to stylesheets. <body> contains everything visible to users.
<!DOCTYPE html>
<html lang="en">
<head>
<title>My Page</title>
</head>
<body>
<h1>Welcome</h1>
</body>
</html>WelcomeA complete, valid HTML5 document structure.
<!DOCTYPE html>
<html>
<body>
<p>Minimal but valid</p>
</body>
</html>Minimal but validThe head is technically optional, but including a title is best practice.
Key points
- <!DOCTYPE html> must be the first line.
- <html> is the root element of the page.
- <head> holds metadata, not visible content.
- <body> contains everything the user sees.
