BRAIZE

A fatal exception 0E has occurred at 0028:C001D00D in VXD BRAIZE(01) + 0000B33F.

The current application will be terminated.

* Press any key to continue

* Press CTRL+ALT+DEL to restart the web. You will lose any unsaved code in all repositories.

Browser Engine Guide.md
Back to guides

Browser Engine Guide :8bit-orpheus:

Want to build a browser engine? Sick. Also: do not try to build Chrome first week. :abc-blahaj:

Browser engines are scary because real ones are huge. But the tiny version is pretty understandable:

HTML text
  -> DOM tree
  -> CSS rules
  -> styled nodes
  -> layout boxes
  -> paint commands
  -> pixels

That is the whole game. Everything else is extra chaos.

This guide pulls ideas from Vertex, a from-scratch C++ browser engine. Vertex is way bigger than what you need, but its structure is useful to copy in tiny form.

The Tiny Goal

Your first engine should render this:

<!doctype html>
<style>
  body { margin: 8px; background: white; color: black; }
  h1 { color: purple; }
  .card { background: yellow; width: 300px; padding: 12px; }
</style>

<h1>Hello Braize</h1>
<p>This page was rendered by my engine.</p>
<div class="card">browser pixels :fire:</div>

If you can parse it, style it, lay it out, and draw boxes/text, you have a real browser-engine project.

Vertex Map

Here is how Vertex names the pieces:

Engine pieceVertex exampleWhat it teaches
DOM treesrc/html/dom.hKeep nodes simple: type, tag, text, attrs, children
HTML parsersrc/html/parser.hOne function can turn HTML into a DOM
CSS rulessrc/css/stylesheet.hRules match nodes, then produce computed style
Layout boxessrc/layout/box.hDOM and layout are separate trees
Paint listsrc/paint/display_list.hPaint can be a list of drawing commands
Debug tooltools/dump_layout.cppYou can test layout without a GUI
Fixturetests/fixtures/render_probe/stacking.in.htmlTiny HTML files make great tests

You do not need all Vertex features. Copy the shape, not the size. :absolute_fire:

Start boring:

src/
  main.*
  dom.*
  html_parser.*
  css_parser.*
  style.*
  layout.*
  paint.*
examples/
  hello.html
README.md

No plugin system. No engine abstraction. No “browser core manager factory”. Tiny pile of files. Good.

Guide Parts

Read these in order:

  1. Part 1: DOM + CSS
  2. Part 2: Layout + Paint

What To Skip At First

Skip these until pixels work:

  • JavaScript
  • networking
  • cookies
  • tabs
  • forms
  • flexbox/grid
  • full HTML5 parser weirdness
  • security sandboxing
  • videos/audio

That stuff matters in real browsers. For your first Braize engine, it is how you drown. :this-is-fine:

Best Submission Shape

Submit with:

  • repo/source
  • examples/hello.html
  • one command to run it
  • screenshot or video
  • README with features + missing features
  • proof trail: commits, notes, screenshots

Great README sentence:

This engine supports basic HTML elements, class/tag/id CSS selectors, block layout, colors, backgrounds, padding, and text painting. It does not support JS, networking, forms, or flexbox yet.

That is honest and reviewable. :party-dinosaur: