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: 76
Dependents: 2
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
Open Issues: 18
pkg:composer/vardumper/extended-htmldocument
Requires
- php: ^8.4
- ext-dom: *
- mnapoli/silly: ^1.9.1
- revolt/event-loop: ^1.0.8
- symfony/yaml: ^7.4.1
Requires (Dev)
- amphp/file: >=3.2
- brainmaestro/composer-git-hooks: dev-master
- edent/pretty-print-html: 2025-04-18
- friendsofphp/php-cs-fixer: ^3.91.3
- 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.33
- rector/swiss-knife: ^2.3.3
- symfony/ux-twig-component: ^2.31
- symplify/easy-coding-standard: ^12.6.2
Suggests
- ext-tidy: Required for formatting HTML5 output.
- dev-main
- 0.2.55
- 0.2.54
- 0.2.53
- 0.2.52
- 0.2.51
- 0.2.50
- 0.2.49
- 0.2.48
- 0.2.47
- 0.2.46
- 0.2.45
- 0.2.44
- 0.2.43
- 0.2.42
- 0.2.41
- 0.2.40
- 0.2.39
- 0.2.38
- 0.2.37
- 0.2.36
- 0.2.35
- 0.2.34
- 0.2.33
- 0.2.32
- 0.2.31
- 0.2.30
- 0.2.29
- 0.2.28
- 0.2.27
- 0.2.26
- 0.2.25
- 0.2.24
- 0.2.23
- 0.2.22
- 0.2.21
- 0.2.20
- 0.2.19
- 0.2.18
- 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/twig-component
- 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-12-12 08:57:34 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
Inside templates/storybook you can find a fully working Storybook boilerplate that includes all HTML5 elements.
Start it with:
cd templates/storybook yarn && yarn storybook
It is supposed to help you as a starting point - helpful when creating a design system. Instead of starting from scratch, you would use the pre-made 'atoms' and thus ensure great consistrncy.
Twig Components Bundle
Symnfony introduced Twig Components as part of the much larger Symfony UX ecosystem.
While maintained and published from the templates/twig-components directory, there is a separate package to install it from.
You will find a Symfony Bundle that brings typesafe, schema-first
Documentation
See the Documentation for more.
Installation
composer require --dev vardumper/extended-htmldocument