HTML as the document layer of the web
HyperText Markup Language describes structure and meaning: elements nest into a tree, attributes annotate nodes, and text/embedded content fills leaves. Browsers parse markup into a DOM, apply CSS for presentation, and execute scripts under Content Security Policy and same-origin rules.
Authors paste HTML from View Source, CMS exports, email builders, or component SSR output—often minified on one line. Pretty-printing exposes nesting for review; minification removes comments and insignificant whitespace. Neither sanitizes untrusted markup nor converts Markdown—that is a separate pipeline.
HTML markup — background
Document tree: elements, attributes, and text
- Documents start with DOCTYPE and an html root; head carries metadata, body carries visible content.
- Start/end tags (or void/self-closing forms) bound regions; attributes are name="value" pairs on the opening tag.
- Text nodes and character references (&, &#…;) live between child elements unless wrapped in CDATA (rare in HTML).
- Semantic tags (main, nav, article) communicate roles to assistive tech when used consistently.
Content models and nesting rules
- Phrasing content (span, a, em) generally nests inside flow content (p, div, li)—putting block inside inline breaks validation in strict parsers.
- Tables use thead/tbody/tr/td/th; lists use ul/ol/li with defined child roles.
- Interactive elements (button, input, select) have focus and form submission semantics distinct from divs with click handlers.
- Template engines may emit non-HTML tokens; parsers expect static markup unless you format compiled output.
Void elements, SVG, and embedded styles
- Void tags (meta, link, img, br, input) have no separate closing tag in HTML syntax.
- Inline SVG uses its own namespace and attributes; it indents with surrounding HTML when the tree is balanced.
- style and script elements embed CSS and JavaScript text—formatting whitespace there does not execute code, but review before paste.
- pre and code preserve significant whitespace; minify between tags may still collapse spaces outside those elements.
How browsers turn markup into an interactive document
- Tokenization emits tags, attributes, and text; tree construction inserts implied elements such as html, head, and tbody where omitted.
- Classic scripts without defer or async pause HTML parsing until they download and execute; defer runs after parse in document order.
- Content Security Policy restricts inline script, eval, and remote origins independently of whether the HTML parser succeeds.
- Mixed-content rules treat passive (img) and active (script) HTTP subresources differently on HTTPS documents.
Where readable HTML helps
Email and CMS template review
Nested tables and conditional comments in email HTML become scannable when indented—still test in real clients after edits.
Landing pages and SSR snippets
One-line SSR output hides section boundaries; formatting clarifies head/body structure before diffing in git.