PHPackages                             webfiori/php-structs - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. webfiori/php-structs

Abandoned → [webfiori/ui](/?search=webfiori%2Fui)Library[Utility &amp; Helpers](/categories/utility)

webfiori/php-structs
====================

A library that provides basic utilities for creating HTML documents.

4.0.1(1mo ago)54.9k[7 issues](https://github.com/WebFiori/ui/issues)MITPHPPHP &gt;=8.1CI passing

Since Apr 25Pushed 3w ago1 watchersCompare

[ Source](https://github.com/WebFiori/ui)[ Packagist](https://packagist.org/packages/webfiori/php-structs)[ RSS](/packages/webfiori-php-structs/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (10)Dependencies (6)Versions (60)Used By (0)

WebFiori UI
===========

[](#webfiori-ui)

A PHP library for creating HTML documents and DOM manipulation with an object-oriented approach.

 [ ![](https://github.com/WebFiori/ui/actions/workflows/php84.yaml/badge.svg?branch=main) ](https://github.com/WebFiori/ui/actions) [ ![](https://camo.githubusercontent.com/7ee2c302e955830b2c7dd95a75cfd521f0391890a5f6163cc99197dd19b8bebc/68747470733a2f2f636f6465636f762e696f2f67682f57656246696f72692f75692f6272616e63682f6d61696e2f67726170682f62616467652e737667) ](https://codecov.io/gh/WebFiori/ui) [ ![](https://camo.githubusercontent.com/55ca623fecab72b811fd1335f39709a83ba849fe1d48e7b7bad1e7fd9ef17d90/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d57656246696f72695f7569266d65747269633d616c6572745f737461747573) ](https://sonarcloud.io/dashboard?id=WebFiori_ui) [ ![](https://camo.githubusercontent.com/777d06983dcb637907b3930d79a75c1b2882657cabdd60e2dd26814480a3e8ce/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f57656246696f72692f75692e7376673f6c6162656c3d6c6174657374) ](https://github.com/WebFiori/ui/releases) [ ![](https://camo.githubusercontent.com/6deafe88276e7b71498ebddc3b23beb47d95c5d1734ccb329ef8cdb7fdff245e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f77656266696f72692f75693f636f6c6f723d6c696768742d677265656e) ](https://packagist.org/packages/webfiori/ui) [![PHP 8.1+](https://camo.githubusercontent.com/6518db1335bf20fdff07253dc6d6d0cec955b5fb6a8ef1382ac6d73687ecc07f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d626c7565)](https://camo.githubusercontent.com/6518db1335bf20fdff07253dc6d6d0cec955b5fb6a8ef1382ac6d73687ecc07f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d626c7565)

Motivations
-----------

[](#motivations)

PHP's built-in `DOMDocument` works but has friction for HTML generation:

- **Verbose** — Creating a styled element with text takes 4-5 lines. This library does it in one: `new HTMLNode('div', ['class' => 'x'])->text('hello')`
- **No chaining** — `DOMDocument` returns void on most mutations. This library is fluent.
- **HTML5 issues** — `DOMDocument` is XML-based (libxml2), throws warnings on HTML5 tags, and mishandles void elements
- **No templates** — No built-in support for loading partial HTML with variable slots
- **Limited output control** — `saveHTML()` gives little control over formatting, quoting, or self-closing tags

This library's sweet spot is *generating* HTML from PHP — pages, emails, components — where a builder pattern and template system give better DX than the W3C DOM API.

> **This is a DOM builder, not a text-based template engine.** If you need template inheritance, compiled templates, or a dedicated syntax (like Blade or Twig), use those instead. Use this library when you want to construct and manipulate HTML programmatically — server-rendered components, email generation, PDF markup, or any case where the structure is driven by logic rather than a layout file.

Table of Contents
-----------------

[](#table-of-contents)

- [Key Features](#key-features)
- [Supported PHP Versions](#supported-php-versions)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Usage](#usage)
    - [HTML Document Creation](#html-document-creation)
    - [Working with Elements](#working-with-elements)
    - [Forms and Input](#forms-and-input)
    - [Tables and Data](#tables-and-data)
    - [Template System](#template-system)
- [API Reference](#api-reference)
- [Testing](#testing)
- [Contributing](#contributing)
- [License](#license)
- [Support](#support)
- [Changelog](#changelog)

Key Features
------------

[](#key-features)

- **Object-Oriented DOM Creation** — Build HTML elements using intuitive PHP classes
- **Template System** — Support for both HTML templates with slots and PHP templates
- **Iterator Support** — Traverse child nodes using foreach loops
- **Type Safety** — Full type hints and comprehensive PHPDoc documentation
- **Security First** — Built-in HTML entity escaping in attribute values
- **XML Support** — Generate both HTML and XML documents
- **Standalone Renderer** — `HtmlRenderer` with per-instance config, safe for async contexts

Supported PHP Versions
----------------------

[](#supported-php-versions)

Build Status[![](https://github.com/WebFiori/ui/actions/workflows/php81.yaml/badge.svg?branch=main)](https://github.com/WebFiori/ui/actions/workflows/php81.yaml)[![](https://github.com/WebFiori/ui/actions/workflows/php82.yaml/badge.svg?branch=main)](https://github.com/WebFiori/ui/actions/workflows/php82.yaml)[![](https://github.com/WebFiori/ui/actions/workflows/php83.yaml/badge.svg?branch=main)](https://github.com/WebFiori/ui/actions/workflows/php83.yaml)[![](https://github.com/WebFiori/ui/actions/workflows/php84.yaml/badge.svg?branch=main)](https://github.com/WebFiori/ui/actions/workflows/php84.yaml)[![](https://github.com/WebFiori/ui/actions/workflows/php85.yaml/badge.svg?branch=main)](https://github.com/WebFiori/ui/actions/workflows/php85.yaml)Installation
------------

[](#installation)

```
composer require webfiori/ui
```

Quick Start
-----------

[](#quick-start)

```
