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.
- 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
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
This browser implementation follows these W3C specifications:
- HTML5: Tokenization and parsing (HTML5 §12)
- CSS 2.1: Syntax, selectors, cascade, box model, and visual formatting
- RFC 2397: The "data" URL scheme for inline resources
go build ./cmd/browser# 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.htmlThe 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.
Example of styled HTML with borders, colors, and text formatting:
Latest Hacker News render (1024x768):
go test ./...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 8080See wasm/README.md for more details.
- MILESTONES.md - Implementation milestones and progress tracking
- IMPLEMENTATION.md - Detailed implementation summary and architecture
- TESTING.md - Testing strategy and public test suite integration
✅ 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.
MIT


