PHPackages                             8fold/php-html-builder - 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. 8fold/php-html-builder

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

8fold/php-html-builder
======================

A library for building HTML document and element strings.

2.4.0(3y ago)12.6k[1 issues](https://github.com/8fold/php-html-builder/issues)1MITPHPPHP ^8.1

Since Oct 8Pushed 2y ago1 watchersCompare

[ Source](https://github.com/8fold/php-html-builder)[ Packagist](https://packagist.org/packages/8fold/php-html-builder)[ GitHub Sponsors](https://github.com/8fold)[ GitHub Sponsors](https://github.com/joshbruce)[ RSS](/packages/8fold-php-html-builder/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (20)Used By (1)

8fold HTML Builder for PHP
==========================

[](#8fold-html-builder-for-php)

HTML Builder extends and is a web-specific implementation of [8fold XML Builder](https://github.com/8fold/php-xml-builder); similar to how HTML extends and is a specific implementation of XML.

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

[](#installation)

`composer require 8fold/php-html-builder`

Usage (basic)
-------------

[](#usage-basic)

Warning: Users of this library are responsible for sanitizing content.

By default, HTML Builder can quickly output an HTML string with consistent ordering of attributes for elements. The default order can be found in the [`Element`](https://github.com/8fold/php-html-builder/blob/main/src/Element.php)class, which can be overridden, if you prefer a different ordering. This helps create and maintain a consistent HTML pattern. Further, this pattern can be changed without updating templates or other code.

```
use Eightfold\HTMLBuilder\Document;
use Eightfold\HTMLBuilder\Element;

Document::create('title')
  ->head(
    Element::link()
      ->omitEndTag()->props('rel stylesheet', 'href style.css'),
    Element::script()->props('src script.js')
  )->body(
    Element::p('paragraph content')
  )
```

Output:

```

titleparagraph content
```

Output (formatted):

```

    title

    paragraph content

```

Further examples can be found in the [`tests`](https://github.com/8fold/php-html-builder/tree/main/tests) folder with an example extension.

A note on properties: If a property is not in the ordered list, and the value of the property is the same as the name of the property, HTML Builder will presume it's a boolean value and will truncate the definition in the HTML output.

```
Element::input()->omitEndTag()->props("required required");
```

Output:

```

```

Performance
-----------

[](#performance)

The `/comparisons` folder can be used to run performance tests locally to compare the same output using:

1. straight HTML,
2. standard PHP,
3. PHP HTML Builder alongside standard PHP (the Element class),
4. PHP HTML Builder only (the Document class), and
5. PHP HTML Builder only using PSR-4 autoloading.

These results are from February 26th, 2024:

ConfigurationAverage time in millisecondsMedian time in millisecondsTransfer size in kilobytes10.03996830.00174152.720.09532410.01604801.9931.60265251.46033201.8241.78497691.79189701.7458.99574158.87555201.74Things worth noting (as rough interpretations):

1. PHP being used as a template engine has a negligible impact on speed.
2. Using `require_once` without PSR-4 autoloading decreases speed by roughly 1.5 milliseconds; however, once the code is made available, very little additional cost seems to be present.
3. Using PSR-4 decreases speed by roughly 6 milliseconds; however, ensures everything is present and available.
4. Using PHP HTML Builder Document and Element resulted in 1 kilobyte reduction in packet size. (Increased processing time in milliseconds most likely offset by decreased download time.)

Details
-------

[](#details)

See [8fold XML Builder](https://github.com/8fold/php-xml-builder#readme) for more details.

Other
-----

[](#other)

- [Code of Conduct](https://github.com/8fold/php-html-builder/blob/master/.github/CODE_OF_CONDUCT.md)
- [Contributing](https://github.com/8fold/php-html-builder/blob/master/.github/CONTRIBUTING.md)
- [Governance](https://github.com/8fold/php-html-builder/blob/master/.github/GOVERNANCE.md)
- [Versioning](https://github.com/8fold/php-html-builder/blob/master/.github/VERSIONING.md)
- [Security](https://github.com/8fold/php-html-builder/blob/master/.github/SECURITY.md)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~38 days

Recently: every ~10 days

Total

16

Last Release

1114d ago

Major Versions

0.6.0 → 1.0.02022-02-01

1.1.0 → 2.0.02022-12-11

PHP version history (3 changes)0.5.0PHP ^7.4||^8.0

0.6.0PHP ^8.0

1.1.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/3ff7aa36dc04c5b535cd71eadbf66038401edde0c9dfaa688bec4fc16c6d7e8b?d=identicon)[eightfold](/maintainers/eightfold)

---

Top Contributors

[![joshbruce](https://avatars.githubusercontent.com/u/15252830?v=4)](https://github.com/joshbruce "joshbruce (94 commits)")

---

Tags

domhtmlphp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/8fold-php-html-builder/health.svg)

```
[![Health](https://phpackages.com/badges/8fold-php-html-builder/health.svg)](https://phpackages.com/packages/8fold-php-html-builder)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
