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

Abandoned → [https://github.com/spatie/laravel-html](/?search=https%3A%2F%2Fgithub.com%2Fspatie%2Flaravel-html)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

vdhicts/html-element
====================

Easily create HTML elements from PHP

v3.0.0(4y ago)0155MITPHPPHP ^7.4|^8.0

Since Apr 13Pushed 4y agoCompare

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

READMEChangelog (5)Dependencies (2)Versions (6)Used By (0)

Html Element
============

[](#html-element)

This package allows you to easily create HTML elements from PHP. It's inspired by [David Walsh's blogpost](https://davidwalsh.name/create-html-elements-php-htmlelement-class) but further improved.

```
use Vdhicts\HtmlElement\HtmlElement;

// Create new html element with attribute name
$selectElement = new HtmlElement('select');
$selectElement->setAttribute('name', 'something');
$selectElement->generate();

// Create new html element with text and attribute
$paragraphElement = new HtmlElement('p', 'text', ['class' => 'center']);
```

Requirements
------------

[](#requirements)

This package requires PHP 7.4 or higher.

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

[](#installation)

You can install the package via composer:

```
composer require vdhicts/html-element
```

Usage
-----

[](#usage)

A new html element can be created with:

```
use Vdhicts\HtmlElement\HtmlElement;

$containerElement = new HtmlElement('div');
$containerElement->setAttribute('class', 'container');
```

The element could contain text:

```
$containerElement->setText('Hello World');
```

The element could have one or more attributes:

```
// One attribute
$containerElement->setAttribute('class', 'container');

// Multiple attributes
$containerElement->setAttributes(['class' => 'container', 'role' => 'container']);
```

Or the element could contain another html element:

```
$colElement = new HtmlElement('div', '', ['class' => 'col-md-6']);
$rowElement = new HtmlElement('div', '', ['class' => 'row']);

$rowElement->inject($colElement);
$containerElement->inject($rowElement);
```

The text and attributes can also be added, which merges with existing text or attributes.

Methods
-------

[](#methods)

- `getTag` or `setTag` to request or change the tag.
- `getAttributes` or `getAttribute(attribute)` to retrieve all attributes with their values or one attributes with its value
- `setAttributes` or `setAttribute(attribute, value)` to manipulate all attributes or just one.
- `addAttributeValue` adds a value to an attributes.
- `removeAttributes` or `removeAttribute(attribute)` to remove all attributes or just one.
- `removeAttributeValue(attribute, value)` to remove one value from a attribute.
- `getText`, `addText` or `setText` to retrieve, add or set the inner text.
- `inject` to inject a Element into the current Element.
- `generate` generates the Element and returns its string representation.
- `output` echos the result of `generate`.

Tests
-----

[](#tests)

Unit tests are available in the `tests` folder. Run with:

`composer test`

When you want a code coverage report which will be generated in the `build/report` folder. Run with:

`composer test-coverage`

Contribution
------------

[](#contribution)

Any contribution is welcome, but it should meet the PSR-12 standard and please create one pull request per feature/bug. In exchange, you will be credited as contributor on this page.

Security
--------

[](#security)

If you discover any security related issues in this or other packages of Vdhicts, please email instead of using the issue tracker.

Support
-------

[](#support)

If you encounter a problem with this parser or has a question about it, feel free to open an issue on GitHub.

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

About Vdhicts
-------------

[](#about-vdhicts)

[Vdhicts](https://www.vdhicts.nl) is the name of my personal company for which I work as freelancer. Vdhicts develops and implements IT solutions for businesses and educational institutions.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity72

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 ~447 days

Total

5

Last Release

1534d ago

Major Versions

1.2.0 → 2.0.02018-05-03

2.0.0 → v3.0.02022-03-06

PHP version history (2 changes)1.2.0PHP ^7.0

v3.0.0PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/88d23e7b707d1cfe0eea91c00590613f45e0c75cb0a3ce89354328332e5c0c02?d=identicon)[vdhicts](/maintainers/vdhicts)

---

Top Contributors

[![dvdheiden](https://avatars.githubusercontent.com/u/90568118?v=4)](https://github.com/dvdheiden "dvdheiden (13 commits)")

---

Tags

htmlphp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

2.8k295.3M2.5k](/packages/symfony-property-access)

PHPackages © 2026

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