Skip to main content
LibWeb is SerenityOS’s comprehensive web engine, implementing modern web standards including HTML5, CSS3, JavaScript, and Web APIs. It provides a full-featured browser engine with standards-compliant DOM, rendering, and scripting capabilities.

Architecture Overview

LibWeb is organized into subsystems that mirror web specifications:
  • DOM: Document Object Model and tree structures
  • HTML: HTML parsing, elements, and semantics
  • CSS: Style computation and cascade
  • Layout: Box model and positioning
  • Painting: Rendering pipeline
  • JavaScript: Integration with LibJS
  • Fetch: Network resource loading
  • Web APIs: Canvas, WebGL, Storage, and more

Core Subsystems

DOM (Document Object Model)

class
The root document object representing an HTML or XML document.
Location: LibWeb/DOM/Document.h
LibWeb implements the complete DOM node hierarchy:
  • Node: Base class for all DOM nodes
  • Element: Elements with attributes and tag names
  • Text: Text content nodes
  • Comment: Comment nodes
  • DocumentType: DOCTYPE declarations
  • DocumentFragment: Lightweight document containers
  • Attr: Attribute nodes
Node Operations:

HTML Elements

class
Base class for all HTML elements.
Location: LibWeb/HTML/HTMLElement.h
Common HTML Elements:
  • Layout: HTMLDivElement, HTMLSpanElement
  • Forms: HTMLFormElement, HTMLInputElement, HTMLButtonElement
  • Media: HTMLImageElement, HTMLVideoElement, HTMLAudioElement
  • Semantic: HTMLHeadingElement, HTMLParagraphElement
  • Tables: HTMLTableElement, HTMLTableRowElement
  • Canvas: HTMLCanvasElement

CSS (Cascading Style Sheets)

LibWeb implements a complete CSS3 engine:Subsystems:
  • Parser: CSS syntax parsing
  • Selectors: Complex selector matching
  • Cascade: Specificity and inheritance
  • StyleCompute: Property computation
  • Values: All CSS value types
  • Properties: Individual property handlers
Major Features:
  • Flexbox and Grid layouts
  • CSS animations and transitions
  • CSS transforms (2D and 3D)
  • Media queries
  • Custom properties (CSS variables)
  • Pseudo-classes and pseudo-elements

Layout Engine

LibWeb’s layout engine implements the CSS box model and positioning schemes.
Layout Types:
  • BlockContainer: Block formatting context
  • InlineNode: Inline content
  • FlexFormattingContext: Flexbox layout
  • GridFormattingContext: CSS Grid layout
  • TableBox: Table layout
  • SVGBox: SVG element layout

JavaScript Integration

namespace
Automatic bindings between C++ and JavaScript using Web IDL.LibWeb uses .idl files to generate JavaScript bindings:
The IDL compiler generates wrapper classes for JavaScript access.Location: LibWeb/Bindings/

Web APIs

Implemented Web APIs:
  • Canvas 2D: 2D drawing context
  • WebGL: 3D graphics rendering
  • Web Storage: localStorage and sessionStorage
  • Fetch API: Modern HTTP requests
  • WebSockets: Bidirectional communication
  • Web Animations: Animation API
  • Intersection Observer: Viewport observation
  • Mutation Observer: DOM change observation
  • File API: File and Blob handling
  • Crypto API: Web Cryptography

Major Subsystems

ARIA (Accessibility)

namespace
Accessible Rich Internet Applications support.
Location: LibWeb/ARIA/

Animations

Location: LibWeb/Animations/

CSS Subsystems

Core Components:
  • CSSStyleSheet: Stylesheet representation
  • CSSRule: Style rules (selectors + declarations)
  • CSSStyleDeclaration: Property declarations
  • StyleResolver: Matching and cascade
  • StyleComputer: Computed value generation
Property System:
  • Length values (px, em, rem, %, vh, vw)
  • Colors (named, hex, rgb(), hsl(), etc.)
  • Transforms and animations
  • Filters and effects
Location: LibWeb/CSS/

Fetch API

namespace
Modern HTTP request API.
Location: LibWeb/Fetch/

WebGL

LibWeb provides WebGL 1.0 support through LibGL:
WebGL calls are translated to LibGL OpenGL operations.

Parsing and Tokenization

HTML Parser

LibWeb implements the HTML5 parsing algorithm:
  • Tokenization: Character stream to tokens
  • Tree Construction: Token stream to DOM
  • Error Recovery: Robust error handling
  • Foreign Content: SVG and MathML integration
The parser handles:
  • Document fragments
  • Script execution during parsing
  • Character encodings
  • Quirks mode detection
Location: LibWeb/HTML/Parser/

CSS Parser

Robust CSS3 parsing with error recovery and vendor prefix support.

Event System

class
Base class for objects that can receive events.
Mouse Events:
  • click, dblclick
  • mousedown, mouseup, mousemove
  • mouseenter, mouseleave
Keyboard Events:
  • keydown, keyup, keypress
Form Events:
  • submit, change, input, focus, blur
Document Events:
  • DOMContentLoaded, load, unload
Custom Events:
  • User-defined event types

Rendering Pipeline

The rendering pipeline transforms layout to pixels:
  1. Layout: Compute positions and sizes
  2. Stacking Context: Z-order determination
  3. Paint: Generate display list
  4. Composite: Layer composition
Location: LibWeb/Painting/

Storage APIs

class
Web Storage (localStorage/sessionStorage) implementation.
Location: LibWeb/HTML/Storage.h

SVG Support

Scalable Vector Graphics rendering integrated into the layout engine.
SVG Features:
  • Basic shapes (rect, circle, ellipse, line, polygon)
  • Paths with full path data support
  • Text rendering
  • Gradients and patterns
  • Transformations
  • Clipping and masking
Location: LibWeb/SVG/

Encoding and URLs

class
URL parsing and manipulation.
Location: LibWeb/DOMURL/

FileAPI

class
File and Blob handling for file uploads and processing.
Location: LibWeb/FileAPI/

Performance and Timing

  • Performance API: Navigation and resource timing
  • requestAnimationFrame: Animation scheduling
  • Intersection Observer: Viewport-based loading
  • Resize Observer: Element size changes
Used for performance monitoring and efficient rendering.

Usage Example

Source Location

Directory: Userland/Libraries/LibWeb/ Major Subdirectories:
  • DOM/: Document Object Model
  • HTML/: HTML elements and parsing
  • CSS/: Style system
  • Layout/: Layout engine
  • Painting/: Rendering
  • Bindings/: JavaScript integration
  • Fetch/: Network requests
  • WebGL/: 3D graphics
  • SVG/: Vector graphics
  • ARIA/: Accessibility
  • Animations/: Web Animations API