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

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

hguenot/html-builder
====================

Tiny PHP HTML Builder Library

v1.0.1(7y ago)19AGPL-3.0PHPPHP &gt;=7.1

Since Oct 18Pushed 7y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

PHP HTML Builder
================

[](#php-html-builder)

A simple library to generate HTML fragments with a jquery-like interface.

This library does not parse HTML, and it does not provide element lookup via selectors or otherwise. It is focused on building simple HTML fragments, for example embed codes, while taking care of proper escaping and other simple syntax rules. Its purpose is to replace manual concatenation of strings.

(Fork of  - PHP 7 support and releases)

\###Continuous integration

[![Build Status](https://camo.githubusercontent.com/0044debbff102f9de2988c179a493a36c923cab451a985d46b88fca66ae4624f/68747470733a2f2f7472617669732d63692e6f72672f686775656e6f742f68746d6c2d6275696c6465722e737667)](https://travis-ci.org/hguenot/html-builder)[![Code coverage](https://camo.githubusercontent.com/6a409d9473f74b7d50fd36af96f66ac7089db17234d0451e5ceef06b06a9c3e0/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f686775656e6f742f68746d6c2d6275696c6465722e737667)](https://codecov.io/github/hguenot/html-builder)[![GitHub version](https://camo.githubusercontent.com/41e6487e97b524dce4022dd87e38ff2f446ff1f74a7e6b7a17c99a998cfd8a2f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f686775656e6f742f68746d6c2d6275696c6465722e737667)](https://github.com/hguenot/html-builder/releases)[![Packagist version](https://camo.githubusercontent.com/ef8fb0f4a7063939ce301d9898c73c6733e863c24c204467ab6cc39fc27dc3f6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f686775656e6f742f68746d6c2d6275696c6465722e737667)](https://packagist.org/packages/hguenot/html-builder)

### Examples

[](#examples)

```
function generateBarcodeHtml( $barcode ) {

	$generator = new BarcodeGeneratorHTML();
	$htmlCode = $generator->getBarcode( $$barcode->toString(), $$barcode->getType(), 1, 45 );

	$el = Html::element('div');
	$el->addClass('barcode-container');

	Html::element('div')
		->addClass('barcode-bars')
		->html( $htmlCode )
		->appendTo($el);

	Html::element('div')
		->addClass('barcode-number')
		->text( $normalizedValue->toString() )
		->appendTo($el);

	return $el;
}

public function generateMenu(array $items) {

	$ul = Html::element('ul');

	foreach ( $this->items as $item ) {

		$li = Html::element('li')
			->appendTo( $ul )
			->toggleClass('active', $item['id'] === $this->activeId);

		Html::element('a')
			->attr('href', '/' . $item['url_key'] . '.html')
			->text( $item['title'] )
			->appendTo( $li );

	}

	return (string)$ul;
}
```

### Factory methods

[](#factory-methods)

##### Html::element($tagName)

[](#htmlelementtagname)

Creates an element.

##### Html::comment($text)

[](#htmlcommenttext)

Creates a comment node.

##### Html::text($text)

[](#htmltexttext)

Creates a text node.

### Appending elements

[](#appending-elements)

##### $el-&gt;append($tagNameOrNode)

[](#el-appendtagnameornode)

Add the new element as the last child.

##### $el-&gt;appendTo(Element $target)

[](#el-appendtoelement-target)

Add the element as the targets last child.

##### $el-&gt;prepend($tagNameOrNode)

[](#el-prependtagnameornode)

Add the new element as the first child.

##### $el-&gt;prependTo($Element $target)

[](#el-prependtoelement-target)

Add the element as the targets first child.

### Element Attributes

[](#element-attributes)

##### $el-&gt;attr($name, $value)

[](#el-attrname-value)

Sets the attribute with the given name and value.

##### $el-&gt;attr($name)

[](#el-attrname)

Returns the attribute with the given name.

##### $el-&gt;attr()

[](#el-attr)

Returns all attributes as an associative array.

##### $el-&gt;removeAttr($name)

[](#el-removeattrname)

Removes the attribute with the given name.

### Element html

[](#element-html)

##### $el-&gt;html($str)

[](#el-htmlstr)

Adds a raw html string as a child.

##### $el-&gt;html()

[](#el-html)

Returns the html representation of the content.

##### $el-&gt;\_\_toString() / $el-&gt;toString()

[](#el-__tostring--el-tostring)

Returns the node as html.

### Element text

[](#element-text)

##### $el-&gt;html($str)

[](#el-htmlstr-1)

Adds a text node.

##### $el-&gt;text()

[](#el-text)

Returns the text contents of this node including its descendants.

### Element classes

[](#element-classes)

##### $el-&gt;addClass($class)

[](#el-addclassclass)

Add one or more classes. Multiple classes are separated by a space.

##### $el-&gt;hasClass($class)

[](#el-hasclassclass)

Returns true if the element has the class.

##### $el-&gt;toggleClass($class, $state)

[](#el-toggleclassclass-state)

Remove or add the class.

##### get classes

[](#get-classes)

Use `$el->attr("class")`

### Element tag name

[](#element-tag-name)

##### $el-&gt;getTagname()

[](#el-gettagname)

Returns the tag name.

##### $el-&gt;switchTagname($value)

[](#el-switchtagnamevalue)

Changes the tag name.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 54.5% 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 ~3 days

Total

2

Last Release

2763d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6f980dc7f653be656d2725f6457567a666e792e4173ba57536de674b6f3e291e?d=identicon)[hguenot](/maintainers/hguenot)

---

Top Contributors

[![timostamm](https://avatars.githubusercontent.com/u/4289451?v=4)](https://github.com/timostamm "timostamm (6 commits)")[![hguenot](https://avatars.githubusercontent.com/u/2578010?v=4)](https://github.com/hguenot "hguenot (4 commits)")[![bobjacobsen](https://avatars.githubusercontent.com/u/2774117?v=4)](https://github.com/bobjacobsen "bobjacobsen (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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