PHPackages                             gercoli/htmltags - 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. gercoli/htmltags

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

gercoli/htmltags
================

Easy to use class for creating HTML tags in an OOP way.

v1.0.1(11y ago)059MITPHPPHP &gt;=5.4.0

Since Feb 11Pushed 11y ago1 watchersCompare

[ Source](https://github.com/Gercoli/HTMLTags)[ Packagist](https://packagist.org/packages/gercoli/htmltags)[ RSS](/packages/gercoli-htmltags/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (7)Used By (0)

HTMLTags
========

[](#htmltags)

Easy to use class for creating HTML tags in an OOP way.

Instalation
-----------

[](#instalation)

Include this into your composer.json file:

```
{
    "require": {
        "gercoli/htmltags": "dev-master"
    }
}
```

Using the class
---------------

[](#using-the-class)

The HTMLTags class uses fully qualified name spaces, so for easier use, add `use GErcoli\HTMLTags\HTMLTag` into your php file. Secondly, the class was designed to be easy to use by allowing the chaining of setter methods.

### Example of a simple tag

[](#example-of-a-simple-tag)

```
    // Create an instance.
    $tag_div = new HTMLTag("div");

    // Add Classes A,B,C and remove B (only A & C should remain)
    $tag_div
        ->addClass("classA")
        ->addClass("classB")
        ->addClass("classC")
        ->removeClass("CLASSB")
        ->setAttribute("id","contrainer")
        ->appendContent("This is text inside of the div!");

    // Lets convert this tag to a formatted string!
    echo $tag_div

    // The string should read:
    // This is text inside of the div!
```

### Nesting HTML tags

[](#nesting-html-tags)

```
    // Create a meta description tag.
    $tag_description = (new HTMLTag("meta"))
        ->setAttribute("name","description")
        ->setAttribute("content","this is a \"description\" tag.");

    // Create a title tag.
    $tag_title = (new HTMLTag("title"))
        ->appendContent("This is a page title");

    // Create a head tag and insert the two other tags INSIDE it.
    $tag_head = (new HTMLTag("head"))
        ->appendContent($tag_title)
        ->appendContent($tag_description);

    // Check the markup:
    echo $tag_head;

    /*
     * OUTPUT:
     *
	 *      This is a page title
	 *
     *
     *
     * Notice that using echo will convert the tag and all sub-tags (or children) to strings,
     * automatically escape invalid characters (such as quotes), and indent the tags.
     */
```

### Notes on end tags

[](#notes-on-end-tags)

By default, when you add content to a tag via `->appendContent()` or `->prependContent()` a closing tag will automatically be enabled, however, using `->setClosingTag(false)` will disable a closing tag, and according to the [HTML5 spec](http://www.w3.org/html/wg/drafts/html/master/syntax.html#normal-elements), this is perfectly valid (which is why I have not added a check for this), so be aware of this fact.

### HTML tags with XHTML children

[](#html-tags-with-xhtml-children)

When you echo out a parent tag that has children, the format of the parent tag does not currently cascade down to it's children, and this is by design. There are tags out there, specifically social networks that don't always properly validate non-XHTML tags, and as such when you set a tag to being XHTML, it will remain that way until YOU change it. THIS WILL change in the future, but to keep validators happy, I will leave self-closing tags alone.

TO DO
-----

[](#to-do)

- Better documentation (working on it)
- Implement the ability to parse a style attribute, we don't want duplicate styles.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

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

Total

6

Last Release

4107d ago

Major Versions

v0.1-alpha → v1.0-beta.12015-02-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/48e2c3ac2013742f6201e4364a37a38ce6ec1992aaccb5511de0cd100f64b2b9?d=identicon)[GErcoli](/maintainers/GErcoli)

---

Top Contributors

[![Gercoli](https://avatars.githubusercontent.com/u/1308491?v=4)](https://github.com/Gercoli "Gercoli (34 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[mkusher/padawan

Smart php completion server

2547.2k](/packages/mkusher-padawan)[aliqasemzadeh/livewire-bootstrap-modal

Dynamic Laravel Livewire 3 Bootstrap modals.

4620.5k](/packages/aliqasemzadeh-livewire-bootstrap-modal)[ichhabrecht/core-upgrader

Run upgrade wizards for multiple TYPO3 versions at once

2732.0k](/packages/ichhabrecht-core-upgrader)[brightnucleus/geolite2-country

Composer-packaged version of the free MaxMind GeoLite2 Country database.

2318.0k](/packages/brightnucleus-geolite2-country)

PHPackages © 2026

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