PHPackages                             diffen/justhtml - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. diffen/justhtml

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

diffen/justhtml
===============

Pure-PHP HTML5 parser (JustHTML port) with html5lib compliance

v0.1.3(5mo ago)00MITPHPPHP &gt;=7.4

Since Feb 2Pushed 3w agoCompare

[ Source](https://github.com/diffen/justhtml-php)[ Packagist](https://packagist.org/packages/diffen/justhtml)[ RSS](/packages/diffen-justhtml/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (4)Versions (4)Used By (0)

JustHTML for PHP
================

[](#justhtml-for-php)

PHP HTML5 parser ported from [Emil Stenström's JustHTML](https://github.com/EmilStenstrom/justhtml), targeting PHP 7.4+. Inspired by [Simon Willison's JavaScript port, justjshtml](https://github.com/simonw/justjshtml). It is built for correctness and passes the html5lib test suite (tree builder, tokenizer, serializer, and encoding tests).

Why use JustHTML?
-----------------

[](#why-use-justhtml)

If you're on PHP 8.4+ and don't need edge-case HTML5 correctness (which is most use cases), start with PHP's built-in [`DOM\\HTMLDocument`](https://www.php.net/manual/en/class.dom-htmldocument.php) instead. It's faster and implemented in C, and will be a better fit for many projects. Use JustHTML only if that doesn't meet your needs.

### 1. Correct HTML5 parsing

[](#1-correct-html5-parsing)

- Passes the html5lib test suite (tree builder, tokenizer, serializer, encoding).
- Mirrors browser error handling for malformed HTML.

### 2. PHP-native and portable

[](#2-php-native-and-portable)

- Pure PHP 7.4+ with no extensions required.
- Easy to debug and vendor in any PHP project.

### 3. Query and output utilities

[](#3-query-and-output-utilities)

- CSS selectors via `query()`, `queryFirst()`, and `matches()`.
- HTML, text, and Markdown output helpers for common workflows.

### 4. Event streaming

[](#4-event-streaming)

- Streaming tokenizer events for low-memory, early-exit parsing.

Features
--------

[](#features)

- HTML5-compliant parsing with html5lib test coverage
- DOM-like tree with HTML serialization and text extraction
- CSS selectors with `query()`, `queryFirst()`, and `matches()`
- Markdown conversion via `toMarkdown()`
- Streaming tokenizer API
- Fragment parsing and strict error mode

Requirements
------------

[](#requirements)

- PHP 7.4+ (tested with 7.4, 8.0, 8.1, 8.2, 8.3, 8.4, 8.5)

Installation
------------

[](#installation)

```
composer require diffen/justhtml
```

Non-Composer use: include `src/JustHTML/*.php` with your autoloader and keep `data/` alongside `src/`.

CLI via Homebrew (6.0.0+ requires a one-time trust step, which lets Homebrew run this MIT-licensed formula's install code):

```
brew trust --formula diffen/justhtml/justhtml
brew install diffen/justhtml/justhtml
```

Quickstart
----------

[](#quickstart)

```
