PHPackages                             fischimglas/ptag - 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. fischimglas/ptag

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

fischimglas/ptag
================

PHP HTML abstraction, Create html elements

1.0.5(1y ago)0621MITPHPPHP &gt;=8.1

Since Jul 24Pushed 1y ago1 watchersCompare

[ Source](https://github.com/fischimglas/PTag)[ Packagist](https://packagist.org/packages/fischimglas/ptag)[ Docs](https://github.com/fischimglas/PTag)[ RSS](/packages/fischimglas-ptag/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (3)Versions (6)Used By (1)

PTag
====

[](#ptag)

PHP HTML abstraction, Create html elements

### Installation

[](#installation)

`composer require fischimglas/ptag`

### Usage

[](#usage)

- Create any HTML element with `HtmlFactory::($attributes, $childContent)`
- Add `$element->addClass($className)` and remove `$element->removeClass($className)` css classes
- Set `$element->setAttribute($attrName,$attrValue)` and remove `$element->removeAttribute($attrName)` attributes
- Set `$element->setStyle($attrName,$attrValue)` and remove `$element->removeStyle($attrName)` attributes
- Add attributes with no value `$element->setAttribute($attrName)`
- Clone elements `$element->clone()`
- Chain modifications `$element->clone()->add($anyContent)->addClass('test')`

### Basic example

[](#basic-example)

```
use PTag\HtmlFactory;

echo HtmlFactory::div()
    ->addClass('first-class')
    ->setAttribute('tabindex', 1)
    ->setAttribute('uk-img')
    ->setStyle('background','red')
    ->add(HtmlFactory::a(['href' => '#'], 'Link'))
    ->add(HtmlFactory::img(['src' => 'image.png']));
```

Result: `Link`

### Empty container

[](#empty-container)

If no html tag is defined, the element can be used as empty container. Attributes and classes to the empty container are ignored.

```
use PTag\HtmlFactory;

echo HtmlFactory::empty()
    ->add('Some content')
    ->addClass('notshown');
```

Result: `Some contentLink`

### Configure mode (HTML5 / XHTML)

[](#configure-mode-html5--xhtml)

By default, HTML5 is assumed and trailing slashes on void elements are avoided. For XHTML, use `ElementCf::setMode(ElementCf::MODE_XHML);` to require trailing slashes.

```
use PTag\HtmlFactory;
use PTag\ElementCf;

ElementCf::setMode(ElementCf::MODE_XHML);

echo HtmlFactory::div()
    ->add(HtmlFactory::img(['src' => 'image.png']));
```

Result: ``

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

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

Every ~10 days

Total

5

Last Release

668d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/354923?v=4)[Jvo A. Maurer](/maintainers/fischimglas)[@fischimglas](https://github.com/fischimglas)

---

Top Contributors

[![fischimglas](https://avatars.githubusercontent.com/u/354923?v=4)](https://github.com/fischimglas "fischimglas (24 commits)")

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/fischimglas-ptag/health.svg)

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

###  Alternatives

[spatie/calendar-links

Generate add to calendar links for Google, iCal and other calendar systems

1.0k7.7M10](/packages/spatie-calendar-links)[dillingham/nova-id-link

Links the ID field in Nova

23126.1k](/packages/dillingham-nova-id-link)[opengento/module-saleable

This extension allows to set if a product is saleable and can show its price by scope and customer group.

137.2k](/packages/opengento-module-saleable)

PHPackages © 2026

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