PHPackages                             ratrijs/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. [Templating &amp; Views](/categories/templating)
4. /
5. ratrijs/html-builder

ActiveLibrary[Templating &amp; Views](/categories/templating)

ratrijs/html-builder
====================

Small and easy-to-use class for HTML generation using object-oriented approach.

1.0.0-alpha1(14y ago)181MITPHP

Since May 21Pushed 14y ago1 watchersCompare

[ Source](https://github.com/rATRIJS/HTMLBuilder)[ Packagist](https://packagist.org/packages/ratrijs/html-builder)[ Docs](https://github.com/rATRIJS/HTMLBuilder)[ RSS](/packages/ratrijs-html-builder/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (2)Used By (0)

\# HTMLBuilder - best HTML generation class there is!

**HTMLBuilder** can be used to generate / build HTML using simple object-oriented interface.

Feature and usage run-through
-----------------------------

[](#feature-and-usage-run-through)

Some code snippets that showcase the **HTMLBuilder** features and API.

### Instance retrieval

[](#instance-retrieval)

To start building your HTML you first need to create HTMLBuilder object. Constructor doesn't need any arguments.

There are two ways that you can achieve this:

- new keyword
- HTMLBuilder::dispatch() method

Both of them will achieve the same thing but HTMLBuilder::dispatch() method has the ability to be a one-liner (at least in PHP versions &lt; 5.4).

#### Initialization via new keyword

[](#initialization-via-new-keyword)

```

```

#### Initialization via HTMLBuilder::dispatch() method

[](#initialization-via-htmlbuilderdispatch-method)

```

```

### HTML generation

[](#html-generation)

Almost all instance methods will append a HTML tag to the generated HTML where tag name is method name. These methods support two arguments:

- content - content inside the tag
- attributes - tag attributes as key-value array where key is attribute name and value is attribute value

Both arguments are optional. It's also possible to pass *attributes* as the only argument. Tag will automatically close.

To keep the tag open you have two options:

- use HTMLBuilder::open() method before the tag method
- use HTMLBuilder::open() method and pass tag name and attributes as arguments for this method

#### Instance methods as tags

[](#instance-methods-as-tags)

**php**

```

```

**html**

```
Hello World
```

#### Keeping tags open to build nested HTML

[](#keeping-tags-open-to-build-nested-html)

##### Using HTMLBuilder::open() before tag method

[](#using-htmlbuilderopen-before-tag-method)

**php**

```

```

**html**

```
Hello World
```

##### Using HTMLBuilder::open() and pass tag arguments inside it

[](#using-htmlbuilderopen-and-pass-tag-arguments-inside-it)

**php**

```

```

**html**

```
Hello World
```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

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

5154d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/85f9b5474dcd3582b113adfd350041b49b33dee3336b9fa94f910451450ee9bb?d=identicon)[rATRIJS](/maintainers/rATRIJS)

---

Top Contributors

[![rATRIJS](https://avatars.githubusercontent.com/u/154868?v=4)](https://github.com/rATRIJS "rATRIJS (5 commits)")

---

Tags

generatorhtmlbuilderSimpleOOP

### Embed Badge

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

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

###  Alternatives

[phpoffice/phpword

PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)

7.6k39.0M226](/packages/phpoffice-phpword)[twig/string-extra

A Twig extension for Symfony String

22150.9M219](/packages/twig-string-extra)[infyomlabs/generator-builder

InfyOm Laravel Generator GUI Builder

134443.0k](/packages/infyomlabs-generator-builder)[twig/markdown-extra

A Twig extension for Markdown

12116.2M126](/packages/twig-markdown-extra)[laminas/laminas-view

Fast and type safe HTML templating library with a flexible plugin system supporting multistep template composition

7528.4M263](/packages/laminas-laminas-view)[twig/html-extra

A Twig extension for HTML

789.4M74](/packages/twig-html-extra)

PHPackages © 2026

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