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

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

comsolit/html-builder
=====================

Build html tags with a fluent API

1.0(11y ago)33.4k↓50%2MITPHPPHP &gt;=5.4.0CI failing

Since May 21Pushed 3y ago9 watchersCompare

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

READMEChangelogDependencies (1)Versions (2)Used By (0)

**THIS REPO IS UNMAINTAINED / A NEW MAINTAINER IS NEEDED**
==========================================================

[](#this-repo-is-unmaintained--a-new-maintainer-is-needed)

HTMLBuilder
===========

[](#htmlbuilder)

Lightweight utility class for building small snippets of HTML in PHP.

Examples
--------

[](#examples)

All examples expect a `use Comsolit\HTMLBuilder;` statement.

### Link tag with inner Text

[](#link-tag-with-inner-text)

```
$builder = new HTMLBuilder('a', 'comsolit AG');
$builder->addAttribute('href', 'https://www.comsolit.com');

$this->assertEquals(
    'comsolit AG',
    $builder->build()
);
```

### Input tag without closing tag

[](#input-tag-without-closing-tag)

```
$builder = new HTMLBuilder('input');
$builder
    ->setVoid() // don't build a closing tag
    ->addAttribute('type', 'text')
    ->addAttribute('name', 'some_name');

$this->assertEquals(
    '',
    $builder->build()
);
```

### Tag with inner text

[](#tag-with-inner-text)

```
$builder = new HTMLBuilder('span', 'my text');

$this->assertEquals(
    'my text',
    $builder->build()
);
```

### Using the magic \_\_toString() method

[](#using-the-magic-__tostring-method)

```
$builder = new HTMLBuilder('span');

$this->assertEquals(
    $builder->build(),
    (string)$builder
);
```

### Wrap tags

[](#wrap-tags)

```
$inputBuilder = (new HTMLBuilder('input'))->setVoid();
$labelBuilder = new HTMLBuilder('label', $inputBuilder);

$this->assertEquals(
    '',
    (string)$labelBuilder
);
```

### Encapsulate tags

[](#encapsulate-tags)

```
$inputBuilder = (new HTMLBuilder('input'))->setVoid();
$labelBuilder = $inputBuilder->encapsulate('label');

$this->assertEquals(
    '',
    (string)$labelBuilder
);
```

### Set attribute conditionally

[](#set-attribute-conditionally)

```
$builder = (new HTMLBuilder('input'))
    ->setVoid()
    ->addAttribute('type', 'checkbox')
    ->addAttributeIf(1 + 1 === 3, 'disabled', 'disabled')
    ->addAttributeIf(1 + 1 === 2, 'checked', 'checked');

$this->assertEquals(
    '',
    (string)$builder
);
```

### Special method for classes

[](#special-method-for-classes)

```
$builder = (new HTMLBuilder('span'))
    ->addClass('once')
    ->addClass('multiple')
    ->addClass('multiple');

$this->assertEquals(
    '',
    (string)$builder
);
```

### Add multiple children

[](#add-multiple-children)

```
$builder = new HTMLBuilder('ul');

for ($i = 0; $i < 2; ++$i) {
  $builder->addChild(new HTMLBuilder('li', (string)$i));
}

$this->assertEquals(
    '01',
    (string)$builder
);
```

Related Packages
----------------

[](#related-packages)

We've used this builder already in three projects and than evaluated other packages to decide whether we want to publish this builder or not:

- [QueryPath](http://querypath.org/)
- [FluentDOM](https://github.com/FluentDOM/FluentDOM)
- [php-html-generation-class](http://snipplr.com/view/35538/php--html-generation-class/) - last commit 2012, 9 commits total, not on packagist
- [php-class-html-generator](https://code.google.com/p/php-class-html-generator) - just a snippet, no package
- [phpquery](https://code.google.com/p/phpquery) - last commit 2011
- [ratrijs/html-builder](https://packagist.org/packages/ratrijs/html-builder)
- [howlowck/html-builder](https://packagist.org/packages/howlowck/html-builder)
- [jleagle/html-builder](https://packagist.org/packages/jleagle/html-builder)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

4015d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/330bd5b6615b47b79b7a91898ac6b588b3c055e999c5fa10ee6037a9d801c9c1?d=identicon)[comsolit](/maintainers/comsolit)

---

Top Contributors

[![clecherbauer](https://avatars.githubusercontent.com/u/985388?v=4)](https://github.com/clecherbauer "clecherbauer (1 commits)")

---

Tags

looking-for-maintainerunmaintained

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-livewire-onboard

A Laravel package to help track user onboarding steps

8171.1k](/packages/spatie-laravel-livewire-onboard)

PHPackages © 2026

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