Kick off your book project in 2 hours, get started with GhostAI in 2 hours, or do both! Free live workshops, on Zoom. You’ll leave with a real book project and a clear plan to keep going. Saturday, June 27, 2026.

Leanpub Header

Skip to main content

Idiosyncrasies of the HTML parser

This book is 50% completeLast updated on 2026-06-12

By understanding how the HTML parser works, you will become more confident in writing correct HTML, understand how it affects things for scripting and styling, and recognize how to address some security issues. Additionally, this book may inspire you to implement your own HTML parser.

Minimum price

$7.99

$9.99

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

EPUB
109
Pages
About

About

About the Book

The HTML parser is a piece of software that processes HTML markup and produces an in-memory tree representation (known as the DOM).

The HTML parser has many strange behaviors. This book will highlight the ins and outs of the HTML parser, and contains almost-impossible quizzes.

HTML is not only used by basically all of the web, but it is also part of many modern applications. The HTML parser is part of the foundation of the web platform.

Share this book

Categories

License

Creative Commons Attribution 4.0 International License

Author

About the Author

Simon Pieters

Simon works on web standards and testing the web platform to foster interoperability between web browsers. He is one of the editors of the WHATWG HTML Living Standard, and has helped the research and design of the HTML parser specification.

Contents

Table of Contents

Preface

  1. Intended audience
  2. Definition
  3. Scope
  4. Practical application
  5. About the author
  6. Acknowledgements
  7. Contribute

Chapter 1. Introduction

  1. The DOM, parsing, and serialization
  2. History of HTML parsers
  3. The HTML parser is specified

Chapter 2. The HTML syntax

  1. The doctype
  2. Elements
  3. Documents
  4. Start tags
  5. End tags
  6. Attributes
  7. Optional tags
  8. Character references
  9. CDATA sections
  10. Comments

Chapter 3. The HTML parser

  1. Overview of the HTML parser
  2. Error handling
  3. Detecting character encoding
  4. Preprocessing the input stream
  5. Tokenizer
  6. Tree construction
  7. Tags that are no longer supported

Chapter 4. Scripting complications

  1. Revised overview of the HTML parser
  2. document.write()
  3. Other parser APIs
  4. DOM manipulation

Chapter 5. Serializing

Chapter 6. Security implications

  1. Introduction
  2. Case studies
  3. Best practice

Appendix A. Implementations

Appendix B. Conformance checkers

  1. DTD-based validators
  2. Validator.nu

Appendix C. Microsyntaxes

  1. Numbers
  2. Image map coordinates
  3. Responsive images
  4. Colors
  5. Meta refresh

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub