PHPackages                             boyhagemann/html - 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. boyhagemann/html

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

boyhagemann/html
================

Build up html elements in PHP in a Object Oriented way

212PHP

Since Jul 19Pushed 12y ago2 watchersCompare

[ Source](https://github.com/boyhagemann/Html)[ Packagist](https://packagist.org/packages/boyhagemann/html)[ RSS](/packages/boyhagemann-html/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Html
====

[](#html)

This package makes it easy to build up html elements in PHP in a Object Oriented way. It allowes you to manipulate the basic html structure as easy and managable as possible. After the html is setup, it can be rendered as a string.

The package is divided in three parts:

- \[Elements\] (#the-elements)
- \[Builder\] (#the-html-builder)
- \[Renderer\] (#the-renderer)

How to install
--------------

[](#how-to-install)

The easiest way to use this package is with Composer. Add the following line to your composer.json file:

```
"require": {
	"boyhagemann/html": "dev-master"
}
```

The Elements
------------

[](#the-elements)

This package comes is built on a simple Element class. It has attributes and can hold other elements nested as children.

### Using the elements

[](#using-the-elements)

Starting with a new element is simple

```
use Boyhagemann\Html\Table;

$table = new Table;
```

Change the attributes of an element

```
$table->attr('class', 'fancy-table');
```

You can insert a new element easy

```
$table->insert($tr = new Tr());
```

Insert an element with text

```
$tr->insert(new Td('This is a nice text');
```

You can edit each child element easily

```
$tr->eachChild(function($td, $i) {
	$td->attr('class', 'my-class')
	$td->setValue('My value ' . $i);
});
```

The Html Builder
----------------

[](#the-html-builder)

With the builder you can build the html and manipulate the structure of the elements.

You can insert new elements to a parent element

```
use Boyhagemann\Html\Builder;

$builder new Builder;
$builder->insert(new Table, 'tr');
```

### Register custom elements to the builder

[](#register-custom-elements-to-the-builder)

Register a callback, so you get a fresh instance every time

```
$builder->register('myCustomElement', function() {

	$element = new Element;
	$element->setName('thead');
	$element->attr('class', 'example-class');

	return $element;
}
```

Or register an instance to use the same instance every time

```
$builder->register('myTable', new Table);
```

Or register a class

```
$builder->register('myTd', 'Your\Html\Td');
```

### Use the registered elements

[](#use-the-registered-elements)

Now we can use this element throughout the whole project.

```
$builder->register('table', new Table);

$table  = $builder->resolve('table');
$tr 	= $builder->resolve('tr');
$td 	= $builder->resolve('BoyHagemann\Html\Elements\Td');
```

We can use it to insert elements

```
$builder->insert('myTable', 'myCustomElement', function($thead) {
	$thead->insert(new Td('Title');
	$thead->insert(new Td('Description');
}
```

Or insert multiple elements and edit their properties

```
$builder->insertMultiple('myTable', 'tr', 5, function($tr) {

	// You can edit each table row now
	$tr->attr('class', 'my-row-class');
	$tr->insert(new Td('First value');
	$tr->insert(new Td('Second value');

});
```

The renderer
------------

[](#the-renderer)

Render your html table as... html

```
use Boyhagemann\Html\Renderer;

$renderer = new Renderer;

// The result is a string with valid html
$html = $renderer->render($table);
```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2a43699bf9428b2ee2e827915e14321f44c4cb7e6fbf4c6a3faf086937a852ce?d=identicon)[boyhagemann](/maintainers/boyhagemann)

---

Top Contributors

[![webble](https://avatars.githubusercontent.com/u/5823497?v=4)](https://github.com/webble "webble (24 commits)")[![boyhagemann](https://avatars.githubusercontent.com/u/737610?v=4)](https://github.com/boyhagemann "boyhagemann (1 commits)")

### Embed Badge

![Health badge](/badges/boyhagemann-html/health.svg)

```
[![Health](https://phpackages.com/badges/boyhagemann-html/health.svg)](https://phpackages.com/packages/boyhagemann-html)
```

PHPackages © 2026

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