Build a working web browser from scratch in a few thousand lines of Python
Web Browser Engineering
Pavel Panchekha and Chris Harrelson's Web Browser Engineering is a free online book that walks you through constructing a basic but complete browser in a couple thousand lines of Python. It covers networking and HTTP, HTML parsing, CSS layout, JavaScript-driven interactivity, cookies and XSS/CSRF defenses, plus modern topics like GPU compositing, the event loop, accessibility, and invalidation.
Web browsers are ubiquitous, but how do they work? This book explains, building a basic but complete web browser, from networking to JavaScript, in a couple thousand lines of Python.
- pavpanchekha
Hi folks, one of the authors here. Happy to answer questions. Chris and I wrote the book starting in 2019, and the book was largely done in late 2024, with publication in 2025. In case folks are wondering, literally none of it was AI-written, because the AIs didn't exist yet!
- coreyp_1
Nice.
I'm on the path to building a browser. I had vaguely remembered this site from when it was listed before, but I couldn't find it when looking again. It's bookmarked now. :)
I'm writing my own libraries (because, with AI, why not indulge in low-level fun?), and I'm almost to the layout engine.
So far (all C libraries), I can read multiple image formats, parse HTML/XML and CSS, rasterize text and just about anything that can be required by CSS or SVG. Fonts were fun... I can do TTF but not WOFF yet. I can do some WASM, but no JS engine yet. I do have my Regex engine, though. (I had built WASM first because it's being used for another project). Still a long way to go. Only approx 780K lines spread out across 30 or so libraries written so far.
- kuharich
Past comments: https://news.ycombinator.com/item?id=26707368, https://news.ycombinator.com/item?id=28898157, https://news.ycombinator.com/item?id=41846780