HTML Parsing → DOM
The HTML stream is tokenized into elements and attributes. The DOM tree is built to represent the document’s structure and content.
White background, black text
This page explains how browsers render HTML, CSS, and JavaScript, then introduces JavaScript and several modern frameworks. Examples are minimal and practical.
Browsers parse HTML into a DOM, CSS into a CSSOM, and merge them into a render tree. The layout is calculated and then painted as pixels. JavaScript can modify this structure dynamically.
The HTML stream is tokenized into elements and attributes. The DOM tree is built to represent the document’s structure and content.
CSS rules are parsed into an object model. Cascading rules, inheritance, and specificity determine the final style applied to each element.
The render tree combines the DOM and CSSOM. Layout determines the position and size of each node, then the browser paints pixels to the screen.
Browsers implement the ECMAScript standard, exposing APIs that allow scripts to manipulate the DOM, handle events, and perform network operations.
JavaScript is standardized as ECMAScript. It runs in browsers and other environments like Node.js, providing both language syntax and access to APIs.
Use ES modules with <script type="module"> and the import/export syntax to structure code and manage dependencies.
<button id="hi">Say Hello</button>
<script type="module">
document.getElementById('hi').addEventListener('click', () => {
alert('Hello from ES Modules');
});
</script>
Modern frameworks build upon JavaScript to improve structure, performance, or maintainability.
Adds static typing to JavaScript. Compiles to standard JavaScript for runtime execution.
function greet(name: string): string {
return `Hello, ${name}`;
}
console.log(greet("Ada"));
JSX is a syntax extension that compiles to function calls returning virtual DOM elements.
export default function App() {
return <button onClick={() => alert('Hi')}>Click</button>;
}
A framework emphasizing reactivity and templates.
<script setup>
import { ref } from 'vue'
const count = ref(0)
</script>
<template>
<button @click="count++">Clicked {{ count }}</button>
</template>
A compiler that turns declarative components into efficient vanilla JavaScript code.
<script> let n = 0; </script>
<button on:click={() => n++}>Clicked {n}</button>
A full-featured framework using TypeScript, templates, and dependency injection for enterprise-grade applications.
import { Component } from '@angular/core';
@Component({
selector: 'hello',
template: `<button (click)="onClick()">Click</button>`
})
export class HelloComponent {
onClick() { alert('Hi'); }
}