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

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

italystrap/html
===============

HTML tag and attributes generator in PHP

1.2.0(6y ago)190712MITPHPPHP &gt;=7.2

Since Dec 9Pushed 6y ago1 watchersCompare

[ Source](https://github.com/ItalyStrap/html)[ Packagist](https://packagist.org/packages/italystrap/html)[ RSS](/packages/italystrap-html/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (6)Dependencies (9)Versions (7)Used By (2)

ItalyStrap HTML API
===================

[](#italystrap-html-api)

[![Build Status](https://camo.githubusercontent.com/99268077886aaed8da40ad82def1eda0430f65de53af71bced35139f2d6cf1c8/68747470733a2f2f7472617669732d63692e6f72672f4974616c7953747261702f68746d6c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ItalyStrap/html)[![Latest Stable Version](https://camo.githubusercontent.com/bb120ed019becd554139d2961e495b2bcb699e155d6795411ff8f96e7d7d9f08/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6974616c7973747261702f68746d6c2e737667)](https://packagist.org/packages/italystrap/html)[![Total Downloads](https://camo.githubusercontent.com/ea9350e7df01c54b752305a9fd231acd6005dfdce976982653b270fd067af6e1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6974616c7973747261702f68746d6c2e737667)](https://packagist.org/packages/italystrap/html)[![Latest Unstable Version](https://camo.githubusercontent.com/f2e0ae7db0c863bc20a339353de50b2e18d0f7ea2d4fc9ded0225716178a0f98/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f6974616c7973747261702f68746d6c2e737667)](https://packagist.org/packages/italystrap/html)[![License](https://camo.githubusercontent.com/5dbd96ca0c76048e5c8cf7f596376c3b6692f2e6671f9431bf22eb6feebff9aa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6974616c7973747261702f68746d6c2e737667)](https://packagist.org/packages/italystrap/html)[![PHP from Packagist](https://camo.githubusercontent.com/1f45825be5e38fc3880348ca813b76471cc00ab8a3b863232f0c639f81979608/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6974616c7973747261702f68746d6c)](https://camo.githubusercontent.com/1f45825be5e38fc3880348ca813b76471cc00ab8a3b863232f0c639f81979608/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6974616c7973747261702f68746d6c)

PHP HTML handler the OOP way

Table Of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Basic Usage](#basic-usage)
- [Advanced Usage](#advanced-usage)
- [Contributing](#contributing)
- [License](#license)

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

[](#installation)

The best way to use this package is through Composer:

```
composer require italystrap/html
```

Basic Usage
-----------

[](#basic-usage)

### Attributes Class

[](#attributes-class)

```
use ItalyStrap\HTML\AttributesInterface;

$sut = new AttributesInterface();

$sut->add( 'context', [
    'class'	=> 'color-primary',
    'id'	=> 'unique_id',
] );

// ' class="color-primary" id="unique_id"'
echo $sut->render( 'context' );

$sut->add( 'another_context', [
    'class'	=> '', // This will be skipped because empty
    'attr1'	=> null, // This will be skipped because null
    'attr2'	=> false, // This will be skipped because false
    'attr3'	=> 0, // This will be skipped because 0 is also false
    'id'	=> 'unique_id',
] );
// ' id="unique_id"'
echo $sut->render( 'another_context' );
```

Attributes can be also used with the `get_attr()` and `get_attr_e()` helpers functions under the same namespece.

```
use function ItalyStrap\HTML\{get_attr, get_attr_e};

// Return ' class="someClass"'
$attr = get_attr( 'context', ['class' => 'someClass'] );

// Echo ' class="someClass"'
get_attr_e( 'context', ['class' => 'someClass'] );
```

### `ItalyStrap\HTML\get_attr()`

[](#italystraphtmlget_attr)

Build list of attributes into a string and apply contextual filter on string:

```
use function ItalyStrap\HTML\{get_attr, get_attr_e};

$attr = [
	'id'	=> 'unique_id',
	'class'	=> 'some_class',
];

$output = get_attr( $context, $attr, false );

// id="unique_id" class="some_class"

printf(
	'Title',
	$output
);
```

or

```
Title
```

```
// Title
```

```
use function ItalyStrap\HTML\{open_tag, close_tag, open_tag_e, close_tag_e};

\ItalyStrap\HTML\Tag::$is_debug = false; // If you don't want tu print debug comments
$open = \ItalyStrap\HTML\open_tag( 'test', 'div', [ 'class' => 'btn-primary' ] );
$this->assertStringContainsString( '', $open, '' );
$closed = \ItalyStrap\HTML\close_tag( 'test' );
$this->assertStringContainsString( '', $closed, '' );

\ItalyStrap\HTML\Tag::$is_debug = false;
\ItalyStrap\HTML\open_tag_e( 'test', 'div', [ 'class' => 'btn-primary' ] );
echo 'Content';
\ItalyStrap\HTML\close_tag_e( 'test' );

$this->expectOutputString( 'Content' );
```

### Tag Class

[](#tag-class)

```
use ItalyStrap\HTML\{Tag,AttributesInterface};

Tag::$is_debug = true; // This will print comment  around the output for debugging, you can see it with ctrl + u key in the browser
$sut = new Tag( new AttributesInterface() );

// Some content inside HTML div tags
echo $sut->open( 'some_context', 'div', [ 'class' => 'someClass' ] );
echo 'Some content inside HTML div tags';
echo $sut->close( 'some_context' );

//
echo $sut->void( 'some_other_context', 'input', [ 'type' => 'text' ] );
```

### Filters

[](#filters)

```
use ItalyStrap\HTML\{Tag,AttributesInterface};

$context = 'some_context';

\add_filter("italystrap_{$context}_tag", function( string $tag, string $context, Tag $obj) {
    // Do some staff with $tag
    $new_tag = 'span';
    return $new_tag;
}, 10, 3);

$sut = new Tag( new AttributesInterface() );
echo $sut->open( 'some_context', 'div', [ 'class' => 'someClass' ] );
echo 'Some content inside HTML div tags';
echo $sut->close( 'some_context' );

// Some content inside HTML div tags
```

Advanced Usage
--------------

[](#advanced-usage)

See in [tests](tests) folder for more advance usage.

Contributing
------------

[](#contributing)

All feedback / bug reports / pull requests are welcome.

License
-------

[](#license)

Copyright (c) 2019 Enea Overclokk, ItalyStrap

This code is licensed under the [MIT](LICENSE).

Notes
-----

[](#notes)

- Maintained under the [Semantic Versioning Guide](http://semver.org)

Credits
-------

[](#credits)

> TODO

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% 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 ~17 days

Total

6

Last Release

2264d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/13d145319a065be260ee79e728655780ddd63002e5ac6c317701c8996ec8d94c?d=identicon)[overclokk](/maintainers/overclokk)

---

Top Contributors

[![overclokk](https://avatars.githubusercontent.com/u/4604932?v=4)](https://github.com/overclokk "overclokk (24 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (6 commits)")

---

Tags

phpphp-librarywordpress-php-library

### Embed Badge

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

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

PHPackages © 2026

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