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

ActiveMouf-library[Utility &amp; Helpers](/categories/utility)

mouf/html.tags
==============

This package contains a pure PHP object representation of HTML5 tags. There is one class for each existing HTML tag, and one getter/setter per attribute.

v1.0.0(11y ago)320.4k11MITPHPPHP &gt;=5.4.4

Since Apr 24Pushed 8y ago11 watchersCompare

[ Source](https://github.com/thecodingmachine/html.tags)[ Packagist](https://packagist.org/packages/mouf/html.tags)[ Docs](http://mouf-php.com/packages/mouf/html.tags)[ RSS](/packages/mouf-htmltags/feed)WikiDiscussions 1.0 Synced 2w ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (1)

What is this package?
=====================

[](#what-is-this-package)

This package contains a pure PHP object representation of HTML5 tags. There is one class for each existing HTML tag, and one getter/setter per attribute.

Why bother?
-----------

[](#why-bother)

There are plenty of ways to represent HTML tags as PHP objects, and most of the time, you might not need one class per tag (you can use a generic PHP object representing any HTML tag like [here](http://davidwalsh.name/create-html-elements-php-htmlelement-class), [here](http://www.phpclasses.org/package/1910-PHP-Generate-HTML-document-tags-programatically.html) or , [here](http://code.google.com/p/php-class-html-generator/)).

So why bother with one class per tag?

Well for a few reasons:

- You can have autocompletion when using the tags (if you are using a sensible PHP IDE)
- You can use those tags in dependency injection frameworks (this part might sound completely crazy to you until you learn more about the [Mouf PHP framework](http://mouf-php.com).

List of supported tags
----------------------

[](#list-of-supported-tags)

Basically, all the tags supported and not deprecated in HTML5. You can get a [complete list on the W3C wiki](http://www.w3.org/community/webed/wiki/HTML/Elements).

How to use it?
--------------

[](#how-to-use-it)

\###Basic usage

Pretty easy. You just create a tag using the `new` keyword and use getters and setters to set attributes. Finally, you call the `toHtml()` method to render the tag.

```
$div = new Div();
$div->setId('myDiv');
$div->toHtml();
```

\###Fluent interface

The setter are using a fluent interface, so you can chain several setters if you want:

```
$input = new Input();
$input->setType('text')->setName('company')->setLabel('TheCodingMachine');
$input->toHtml();
```

\###Setting classes and styles

You can set classes and styles using arrays or strings:

```
$label = new Label();
$label->setClasses(array("css-class1 css-class2"));
$label->setStyles(array("background-color" => "red"));
$label->toHtml();
```

You can also add a class or a style using `addClass` or `addStyle`.

```
$label->addClass("css-class3");
$label->addStyle("background-color", "red");
```

\###Managing children

You can add children to your tags using `setChildren` or `addChild`.

```
$div->setChildren(array($label, $input));
```

```
$div->addChild($label);
```

\###Adding text to a tag

Use the `addText` to add text to a tag.

```
$p = new Paragraph();
$p->addText("This is my text");
```

Note: this is similar to creating a `HtmlString` instance and adding it to the node:

```
// Similar to:
$p->addChild(new HtmlString("This is my text"));
```

Adding your own custom tags
---------------------------

[](#adding-your-own-custom-tags)

You might be interested in adding your owns classes that generate custom HTML code. All you have to know is that all the tags are implementing the [`HtmlElementInterface`](http://mouf-php.com/packages/mouf/html.htmlelement/README.md).

This is a simple interface with a single `toHtml()` method.

What is this ValueInterface thing?
----------------------------------

[](#what-is-this-valueinterface-thing)

If you have had a look at the code, you might have noticed that each setter accepts objects implementing the [`ValueInterface` interface](http://mouf-php.com/packages/mouf/utils.value.value-interface/README.md).

This is a very powerful feature allowing you to put objects that will be evaluated when they are rendered. When the tag is rendered, the `val()` method of the object is called and attributed.

Mouf package
------------

[](#mouf-package)

This package is part of [Mouf](http://mouf-php.com), an effort to ensure good developing practices by providing a graphical dependency injection framework.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 69.2% 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 ~0 days

Total

2

Last Release

4078d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1104771?v=4)[mouf](/maintainers/mouf)[@Mouf](https://github.com/Mouf)

---

Top Contributors

[![moufmouf](https://avatars.githubusercontent.com/u/1290952?v=4)](https://github.com/moufmouf "moufmouf (9 commits)")[![nguyenk](https://avatars.githubusercontent.com/u/2227554?v=4)](https://github.com/nguyenk "nguyenk (3 commits)")[![vaidiep](https://avatars.githubusercontent.com/u/2227695?v=4)](https://github.com/vaidiep "vaidiep (1 commits)")

---

Tags

htmlHTML5interfacetagstohtml

### Embed Badge

![Health badge](/badges/mouf-htmltags/health.svg)

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

###  Alternatives

[arcanedev/php-html

A simple way to create html tags with php.

161.0M6](/packages/arcanedev-php-html)[mouf/html.widgets.statsgrid

This PHP package contains a HTML pivot table. You provide it with a data set and the list of columns and rows and it will display a nice pivot table.

2310.0k](/packages/mouf-htmlwidgetsstatsgrid)

PHPackages © 2026

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