HTML Document Essentials
Elements, attributes, the document skeleton, text, links, images and tables: the raw material of every page.
Beginner · about 5 hours · difficulty 1/5
Learn first: How Browsers Render a Page
HTML describes what content is, not how it looks. A browser reads tags like <h1>, <p> and <a> and builds a tree of elements from them.
The skeleton
Every page needs <!doctype html> (standards mode), an <html lang="en"> root, a <head> with <meta charset="utf-8">, the viewport meta tag (width=device-width, initial-scale=1) and a <title>, then a <body> with visible content. Forgetting the viewport tag is the classic reason a site looks tiny on phones.
Everyday elements
- Text: headings
<h1>to<h6>(in order, no skipping for styling),<p>,<strong>,<em>, lists<ul>/<ol>/<li>. - Links:
<a href>with meaningful text; usetarget="_blank"sparingly. - Media:
<img src alt width height>(always setalt, and dimensions to avoid layout shift),<picture>,<video>,<audio>. - Tables for tabular data only, with
<th>,<thead>,<caption>.
Attributes and nesting
Attributes configure elements (id, class, href, data-*). Block-level vs inline is now a CSS concern, but invalid nesting (a <div> inside a <p>) still produces surprising DOM trees because the parser auto-closes tags.
Pitfalls
- Using
<br>or empty paragraphs for spacing (use CSS). <div>and<span>everywhere with no meaning.- Missing
alt, or alt text like "image of".
Move on once you can hand-write a multi-section page from memory and it passes the W3C validator with no errors.
Key concepts
- Doctype, head and body
- Viewport and charset meta tags
- Headings, paragraphs and lists
- Links and navigation
- Images, alt text and media
- Tables for data
- Global and data-* attributes
- HTML validation
Mini project
Hand-write a personal profile page with a bio, a list of skills, a table of projects and embedded images, then run it through the W3C validator until it reports zero errors.
Check yourself
What goes wrong on mobile if you forget the viewport meta tag, and why?
Free resources
- HTML: HyperText Markup Language (MDN)
- Learn HTML (web.dev)
- W3C Markup Validation Service (W3C)