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 today

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 47% 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

4152d ago

Major Versions

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

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1308491?v=4)[Garry Ercoli](/maintainers/GErcoli)[@Gercoli](https://github.com/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

[davidpiesse/nova-maintenance-mode

Enable and disable Maintenance Mode from within Laravel Nova

3364.0k](/packages/davidpiesse-nova-maintenance-mode)[arkhas/laravel5calendar

A calendar with event managment package for laravel 5 using Carbon and Blade templating

161.6k](/packages/arkhas-laravel5calendar)

PHPackages © 2026

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