browser

module
v0.0.0-...-52c3ae2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2026 License: MIT

README

Browser - A Simple Web Browser in Go

CI Go Report Card

A simple web browser implementation in Go, focusing on static HTML and CSS 2.1 compliance. This project aims to stay close to W3C specifications and provide a clean, well-organized codebase for educational purposes.

Features

  • HTML parsing with DOM tree construction
  • CSS 2.1 parsing and style computation
  • Visual formatting model (box model, block layout)
  • High-quality text rendering with Go fonts (proportional sans-serif)
  • Font styling support (bold, italic, underline, size)
  • Image rendering (PNG, JPEG, GIF, SVG support)
  • Data URLs: Support for RFC 2397 data URLs (base64 and URL-encoded)
  • Background and border rendering
  • PNG image output
  • Network support: Load pages via HTTP/HTTPS
  • External CSS: Fetch and apply stylesheets from <link> tags
  • Network images: Load images from remote URLs
  • WebAssembly: Run the browser entirely in a web client

Project Structure

browser/
├── cmd/
│   ├── browser/      # Main CLI browser application
│   └── browser-wasm/ # WebAssembly entry point
├── html/            # HTML tokenization and parsing
├── css/             # CSS parsing
├── dom/             # DOM tree structure
├── style/           # Style computation and cascade
├── layout/          # Layout engine (visual formatting model)
├── render/          # Rendering engine
├── wasm/            # WebAssembly demo page
└── test/            # Test files and fixtures

Specifications

This browser implementation follows these W3C specifications:

Quick Start

Building
go build ./cmd/browser
Running
# Render local HTML file to PNG
./browser -output output.png test/styled.html

# Load and render a web page from URL
./browser -output hn.png https://news.ycombinator.com/

# View layout tree without rendering (text output)
./browser test/styled.html

# Custom viewport size
./browser -output output.png -width 1024 -height 768 test/hackernews.html

Screenshots

Font Rendering

The browser uses the Go fonts - high-quality, proportional, sans-serif fonts designed for the Go project. These fonts are embedded in the binary and provide excellent readability with support for bold, italic, and various sizes.

Font Comparison

Test Case Rendering

Example of styled HTML with borders, colors, and text formatting:

Test Case Rendering

Hacker News

Latest Hacker News render (1024x768):

Hacker News Rendering

Testing
go test ./...

WebAssembly

The browser can be compiled to WebAssembly and run entirely in a web browser. A live demo is available at https://lukehoban.github.io/browser/ and is automatically deployed via GitHub Actions.

To build locally:

GOOS=js GOARCH=wasm go build -o wasm/browser.wasm ./cmd/browser-wasm
cd wasm && python3 -m http.server 8080

See wasm/README.md for more details.

Documentation

Current Status

✅ Milestones 1-7 Complete: Foundation, HTML Parsing, CSS Parsing, Style Computation, Layout Engine, Rendering, Image Rendering
✅ Milestone 9 Complete: Network Support (HTTP/HTTPS, external CSS, remote images)
✅ Milestone 9.5 Complete: Data URL Support (RFC 2397, base64 & URL-encoded inline resources)
🔄 Milestone 8 In Progress: Testing & Validation (81.8% WPT pass rate)

See MILESTONES.md for detailed progress and known limitations.

License

MIT

Directories

Path Synopsis
cmd
browser command
Package main provides the browser command-line application.
Package main provides the browser command-line application.
browser-wasm command
Package main provides a WebAssembly entry point for the browser.
Package main provides a WebAssembly entry point for the browser.
wptrunner command
Command wptrunner runs WPT reference tests against the browser implementation.
Command wptrunner runs WPT reference tests against the browser implementation.
Package css provides CSS parsing and stylesheet management.
Package css provides CSS parsing and stylesheet management.
Package dom provides resource loading functionality for the Document Object Model.
Package dom provides resource loading functionality for the Document Object Model.
Package font provides font loading and text measurement utilities.
Package font provides font loading and text measurement utilities.
Package html provides HTML tokenization and parsing.
Package html provides HTML tokenization and parsing.
Package layout implements the CSS 2.1 visual formatting model.
Package layout implements the CSS 2.1 visual formatting model.
Package log provides a simple internal logging library with no external dependencies.
Package log provides a simple internal logging library with no external dependencies.
Package reftest provides a test harness for running WPT (Web Platform Tests) reference tests against this browser implementation.
Package reftest provides a test harness for running WPT (Web Platform Tests) reference tests against this browser implementation.
Package render implements the rendering engine for the browser.
Package render implements the rendering engine for the browser.
Package style handles style computation and the CSS cascade.
Package style handles style computation and the CSS cascade.
Package svg provides scanline rasterization for SVG shapes.
Package svg provides scanline rasterization for SVG shapes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL