Learning Goals
- Understand how browsers load and parse an HTML file.
- Learn about the rendering process (DOM, CSSOM, Render Tree).
- Recognize why clean, valid HTML is important.
1 — The Browser’s Job
When you type a URL or open an HTML file, the browser:
- Fetches the HTML file.
- Parses it into a tree-like structure (the DOM).
- Loads resources referenced in HTML (CSS, JS, images).
- Builds the page combining DOM (structure), CSSOM (styles), and JS (behavior).
- Paints the final pixels on your screen.
2 — Example: Simple HTML → Render
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Browser Demo</title>
<style>
body { background:#121212; color:#eee; }
h1 { color: cyan; }
</style>
</head>
<body>
<h1>Browser Rendering</h1>
<p>The browser parses HTML into a DOM, applies CSS, and executes JS.</p>
<script>
console.log("Page loaded!");
</script>
</body>
</html>
The browser turns this code into a structured page with styled text, then runs the script.
Live Preview
3 — Why This Matters
- Broken HTML → unpredictable rendering.
- Invalid nesting → browser may auto-correct incorrectly.
- Performance → fewer blocking resources = faster rendering.
Tip: Use browser DevTools (F12) to see the DOM the browser created. Check the Elements and Console tabs.
Practice Task
- Create a simple HTML file with a heading, paragraph, and image.
- Open the DevTools “Elements” tab to inspect the DOM structure.
- Try breaking a tag (like leaving off
</p>
) and see how the browser fixes it. - Check the “Console” tab to see any errors or messages.
Quick Quiz
- What does the browser build when it parses HTML?
- What happens if HTML is invalid or mis-nested?
- What three things combine to form the Render Tree?
Lesson 3 Dictionary
- Browser
- The application that fetches, parses, and renders web pages.
- Blocking resource
- A resource (often CSS/JS) that delays the render until it’s loaded/processed.
- Broken HTML
- Invalid or malformed markup that can cause unpredictable rendering.
- CSS
- Stylesheet language controlling presentation (colors, layout, spacing).
- CSSOM
- Tree of parsed CSS rules combined with the DOM to build the render tree.
- Console
- DevTools tab showing logs, warnings, and errors from scripts.
- DevTools
- Built-in browser tools used to inspect and debug pages.
- DOM
- Document Object Model — the tree built by parsing HTML.
- Fetch
- Retrieving a resource (like an HTML file) over the network or filesystem.
- HTML
- Markup language that provides the structure and semantics of web pages.
- Invalid nesting
- Placing elements in disallowed positions, forcing the parser to auto-correct.
- JavaScript (JS)
- Programming language used for behavior; interacts with the DOM and CSSOM.
- Parse / Parser
- The process/tool that reads HTML/CSS and builds the corresponding trees.
- Paint
- Stage where the browser fills pixels (text, colors, borders) onto layers.
- Performance
- How fast a page renders/responds; impacted by blocking resources.
- Render Tree
- Structure created by combining the DOM and CSSOM for layout/paint.
- Resources
- External files referenced by HTML, including CSS, JavaScript, and images.
- URL
- The address the browser loads when fetching a page or resource.