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

ActiveLibrary

aviator/html
============

3.0.5(5y ago)02.0k↑288.2%MITPHPPHP &gt;=7.2.0

Since Oct 11Pushed 5y ago1 watchersCompare

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

READMEChangelog (10)Dependencies (6)Versions (30)Used By (0)

[![travis-badge](https://camo.githubusercontent.com/470ef7e9fe219645d26aace7617c6c3f644a0f564a069e64765618aa6c1895a4/68747470733a2f2f7472617669732d63692e6f72672f64616e69656c736465626f65722f68746d6c2e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/470ef7e9fe219645d26aace7617c6c3f644a0f564a069e64765618aa6c1895a4/68747470733a2f2f7472617669732d63692e6f72672f64616e69656c736465626f65722f68746d6c2e7376673f6272616e63683d6d6173746572)[![Latest Stable Version](https://camo.githubusercontent.com/3a1bd731b4615dbf92ac011389826b7b58cf49551b8e454568cea67a4db612a5/68747470733a2f2f706f7365722e707567782e6f72672f61766961746f722f68746d6c2f762f737461626c65)](https://packagist.org/packages/aviator/html)[![License](https://camo.githubusercontent.com/3ff8c502c7a426b949024fc0277c6fde44f9ff110fd349f0d513b787e1f029e3/68747470733a2f2f706f7365722e707567782e6f72672f61766961746f722f68746d6c2f6c6963656e7365)](https://packagist.org/packages/aviator/html)

Html
====

[](#html)

Html is a simple package for building snippets of valid HTML. It can be used to augment a templating system where you want to encapsulate more logic in a class vs a template file.

Getting Started
---------------

[](#getting-started)

### Prerequisites

[](#prerequisites)

This package requires PHP 7 or higher.

### Installing

[](#installing)

Via Composer:

```
composer require aviator/html

```

### Testing

[](#testing)

Run:

```
composer test
```

Usage
-----

[](#usage)

### Tags

[](#tags)

To build a block of HTML, make a new tag:

```
$tag = new Tag('div');
```

Or, using the static constructor:

```
$tag = Tag::make('div');
```

Or, using magic static calls:

```
$tag = Tag::div();
```

Or, using the global helper function:

```
$tag = tag('div');
```

To render the tag, call `render()`:

```
echo $tag->render();
```

Which produces:

```

```

The `Tag` class will only accept valid HTML tags. Trying to create an invalid tag will throw an exception.

Content
-------

[](#content)

Tags can have contents. You can pass in a string, a `Tag`, or an array of either or both.

### Strings

[](#strings)

Use the `with()` method to add content to a tag:

```
$tag = tag('div')->with('some content');
```

This will render as:

```
some content
```

Additionally, `with()` will attempt to get a string representation of any non-string, non-renderable passed in, including objects that implement `__toString()`.

### Nested Tag

[](#nested-tag)

Tags can be nested:

```
$tag = tag('div')->with(
    tag('p')->with('some content')
);
```

Render:

```
some content
```

### Array

[](#array)

You can also use an array:

```
$tag = tag('ul')->with([
    tag('li')->with('list item 1'),
    tag('li')->with('list item 2'),
    'misplaced text',
]);
```

Which will render:

```

  list item 1
  list item 2
  misplaced text

```

### Void tags

[](#void-tags)

The `Tag` class knows which tags are void and need no closing tag. There's no need to do anything for ``, ``, etc.

Void tags cannot have content. Trying to add content to them will throw an exception.

### Fragments

[](#fragments)

Direct siblings can be rendered using a `Fragment`. A fragment is simply an un-nested collection of tags (or other renderables, even other fragments):

```
$fragment = new Fragment([
    new Tag('p'),
    new Tag('div'),
]);

// Or Fragment::make([...]);
```

`$fragment->render()`:

```

```

### Conditional Tags

[](#conditional-tags)

You can create a conditional tag that will only render sometimes:

```
$tag = new Tag('div');

// Evaluates equality, eg truthy and falsey values
$tag->setShouldRender(false);
```

or

```
$tag = Tag::when(false, 'div');
```

`$tag->render()`:

```
''
```

CSS Classes
-----------

[](#css-classes)

To specify CSS classes for your tags, pass in a second parameter:

```
$tag = tag('div', 'some-class');
```

Render:

```

```

Multiple CSS classes may be passed in via array:

```
$tag = tag('div', ['class-one', 'class-two'])
```

Render:

```

```

### After instantiation

[](#after-instantiation)

If you need to add classes after instantiation, you can call `addClass()`, which accepts the same string or array as the constructor:

```
$tag = tag('div');

$tag->addClass('some-class');
$tag->addClass(['class2', 'class3']);
```

Attributes
----------

[](#attributes)

Attributes are passed in as the third parameter. Attributes with values are passed by association. Boolean attributes are simply a value.

```
$tag = tag('input', 'some-class', [
    'value' => 'content',
    'disabled'
]);
```

Render:

```

```

### After instantiation

[](#after-instantiation-1)

If you need to add attributes after instantiation, you can call `addAttribute()`, which accepts the same array as the constructor:

```
$tag = tag('input');

$tag->addAttribute(['autocomplete' => 'off']);
$tag->addAttribute(['disabled']);
```

### Validation

[](#validation)

Attributes are validated to make sure they belong to the tag you've applied them to. For instance adding the `max` attribute to a `` will throw an exception.

### Getting attribute values

[](#getting-attribute-values)

If you want to retrieve an attribute from a `Tag` instance, call `attribute($name)`. If your attribute exists you'll get the value (boolean attributes always return `true`), otherwise you'll get null.

```
echo tag('input')->addAttribute(['name' => 'some_name'])->attribute('name');

// Result: 'some_name'

echo tag('input')->addAttribute(['disabled'])->attribute('disabled');

// Result: true

echo tag('input')->attribute('foo');

// Result: null
```

### Options

[](#options)

If you want to render an open tag, call the `dontClose()` method:

```
echo tag('div')->dontClose()->render()
```

Result:

```

```

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity69

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

Recently: every ~114 days

Total

28

Last Release

1977d ago

Major Versions

1.15 → 2.0.02018-08-21

2.2.1 → 3.0.02019-09-09

PHP version history (2 changes)1.0PHP &gt;=7.0.0

2.2.0PHP &gt;=7.2.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/ebd3fe214b5768e700ae43c7fdc4b83d249972a6a97a0faef372d0ec19256eca?d=identicon)[danielsdeboer](/maintainers/danielsdeboer)

---

Top Contributors

[![danielsdeboer](https://avatars.githubusercontent.com/u/13170241?v=4)](https://github.com/danielsdeboer "danielsdeboer (29 commits)")

---

Tags

htmlphpphp7

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[cviebrock/eloquent-sluggable

Easy creation of slugs for your Eloquent models in Laravel

4.0k13.6M251](/packages/cviebrock-eloquent-sluggable)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[spiral/framework

Spiral, High-Performance PHP/Go Framework

2.0k1.8M57](/packages/spiral-framework)[shopware/storefront

Storefront for Shopware

684.2M148](/packages/shopware-storefront)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[bolt/core

🧿 Bolt Core

585142.5k54](/packages/bolt-core)

PHPackages © 2026

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