vardumper / extended-htmldocument
ExtendedHTMLDocument is a simple PHP library which adds all HTML5 Elements as PHP classes and extends PHP 8.4's DOM\HTMLDocument class.
Fund package maintenance!
vardumper
Buymeacoffee
www.patreon.com/vardumper
Installs: 48
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
Open Issues: 8
pkg:composer/vardumper/extended-htmldocument
Requires
- php: ^8.4
- ext-dom: *
- mnapoli/silly: ^1.9.1
- revolt/event-loop: ^1.0.7
- symfony/yaml: ^7.3.5
Requires (Dev)
- amphp/file: >=3.2
- brainmaestro/composer-git-hooks: dev-master
- edent/pretty-print-html: 2025-04-18
- friendsofphp/php-cs-fixer: ^3.89.1
- pestphp/pest: ^3.8.4
- pestphp/pest-plugin-drift: ^3.0
- pestphp/pest-plugin-type-coverage: ^3.6.1
- phpmd/phpmd: ^2.15
- phpstan/phpstan: ^2.1.31
- rector/swiss-knife: ^2.3.3
- symplify/easy-coding-standard: ^12.6.2
Suggests
- ext-tidy: Required for formatting HTML5 output.
- dev-main
- 0.2.17
- 0.2.16
- 0.2.15
- 0.2.14
- 0.2.13
- 0.2.12
- 0.2.11
- 0.2.10
- 0.2.9
- 0.2.8
- 0.2.7
- 0.2.6
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.27
- 0.1.26
- 0.1.25
- 0.1.24
- 0.1.23
- 0.1.22
- 0.1.21
- 0.1.20
- 0.1.19
- 0.1.18
- 0.1.17
- 0.1.16
- 0.1.15
- 0.1.14
- 0.1.13
- 0.1.12
- 0.1.11
- 0.1.10
- 0.1.9
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-feature/codacy-patch
- dev-develop
- dev-copilot/fix-25
- dev-copilot/fix-23
- dev-feature/6-handle-mutliple-attributes-with-same-name-correctly
This package is auto-updated.
Last update: 2025-11-09 21:10:58 UTC
README
Extended HTML Document Library
This library provides a way to work with HTML elements in PHP, offering an object-oriented approach that aligns with the HTML5 specifications. It also provides a way to automatically transform HTML into different templating engines or code for frontend frameworks. It also adds autocompletion to PHP for all HTML5 elements, which is especially useful when working with DOM Documents. It adds additional functionality and a stronger focus on HTML5 while being fully compatible with PHP's DOM\HTMLDocument and DOM\HTMLElement classes.
TL;DR
This library adds the HTML5 specification to PHP and is fully compatible with DOM\HTMLDocument. You can create an Anchor() object and append it to any DOM\Document.
use Html\Delegator\HTMLDocumentDelegator as HTMLDocument; use Html\Element\Inline\Anchor; $dom = HTMLDocument::createEmpty() echo (string) Anchor::create($dom) ->setClass('secondary') ->setRel(RelEnum::NOFOLLOW) ->setHref('https://google.com') ->setTitle('Google it'); // output is: // <a class="secondary" href="https://google.com" rel="nofollow" title="Google it"></a>
Generated Templates
Templates are generated from the HTML5 schema for every HTML element. These allow for better consistency in your design system(s), support all possible HTML attributes and have basic validations for enum attributes.
Files are grouped into inline, block and void elements. For elements with a specific content model, a composed template is generated as well. (eg <table><tr><td>Cell</td><tr></table>)
Twig
They are compatible with different ways of using Twig (include, embed and use).
$twig->path('vendor/vardumper/extended-htmldocument/templates', 'html'); /** register template path with or without namespace */
Example
{% include '@html/inline/a.twig' with {
href: 'https://example.com',
title: 'Some info about the link'
rel: 'nofollow',
role: 'button',
content: '<strong>Click here</strong>'
} %}
React & NextJS
Type-safe, auto-generated React components for all HTML5 elements with full ARIA support. Work in both Next.js (Server Components, Client Components) and regular React applications (CRA, Vite, etc.). They use pure functional React patterns without hooks or browser-specific APIs. Example:
import { Button, Div, H1 } from './index'; export default function Page() { return ( <Div className="container"> <H1>Welcome</H1> <A href="/contact" > Contact us </A> </Div> ); }
Storybook
Documentation
See the Documentation for more.
Installation
composer require --dev vardumper/extended-htmldocument