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

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

kylekatarnls/html-object
========================

A set of classes to create and manipulate HTML objects abstractions

1.5.2(3y ago)2326.7k—4.5%12MITPHPPHP &gt;=5.3.0

Since Jun 6Pushed 3y agoCompare

[ Source](https://github.com/kylekatarnls/html-object)[ Packagist](https://packagist.org/packages/kylekatarnls/html-object)[ GitHub Sponsors](https://github.com/kylekatarnls)[ Fund](https://opencollective.com/Carbon)[ RSS](/packages/kylekatarnls-html-object/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (3)Dependencies (4)Versions (15)Used By (2)

HTMLObject
==========

[](#htmlobject)

[![Unit tests](https://github.com/kylekatarnls/html-object/actions/workflows/test.yml/badge.svg)](https://github.com/kylekatarnls/html-object/actions)[![Latest Stable Version](https://camo.githubusercontent.com/9544c035abe027c4f203b34730318d5dd078475e0db7f550b1272f05f18b0dfa/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b796c656b617461726e6c732f68746d6c2d6f626a6563742e7376673f7374796c653d666c6174)](https://packagist.org/packages/kylekatarnls/html-object)[![codecov.io](https://camo.githubusercontent.com/0f6b7e44ffa1276d8417543b2a74edfe1637b0faff58ac12a033a1454428ad8b/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6b796c656b617461726e6c732f68746d6c2d6f626a6563742e737667)](https://app.codecov.io/gh/kylekatarnls/html-object)

HTMLObject is a set of classes to create and manipulate HTML objects abstractions.

Forked from [Anahkiasen/html-object](https://github.com/Anahkiasen/html-object)

Install
-------

[](#install)

```
composer require kylekatarnls/html-object

```

Static calls to the classes
---------------------------

[](#static-calls-to-the-classes)

```
echo Element::p('text')->class('foobar');
// text
```

```
$list = List::ul(array('foo', 'bar'));

$link = Link::create('#', 'Someone');
$list->getChild(0)->addClass('active')->setValue('by '.$link);
//
//   foo
//   by Someone
//
```

```
echo Link::create('#foo', 'link')->class('btn btn-success')->blank();
// link
```

Extending the core classes
--------------------------

[](#extending-the-core-classes)

The core classes are meant to be extended and used to create complex patterns. All classes implement tree-crawling properties such as the following :

```
$element = Element::figure();

$element->nest('content') // content

$element->nest('p', 'content') // content

$image = Image::create('img.jpg')->alt('foo'); //
$element->setChild($image, 'thumb');

$element->getChild('thumb') // HtmlObject\Image
$element->nest(array(
  'caption' => Element::figcaption()->nest(array(
    'text' => Element::p('foobar'),
  )),
));

$element->getChild('caption.text')->getValue() // foobar
// OR
$element->captionText->getValue() // foobar
$element->captionText->getParent(0) // figure->caption
$element->captionText->getParent(1) // figure

$element->wrap('div') // ...
$element->wrapValue('div') // ...
```

You can see examples implementations in the [examples](examples) folder.

### Properties injection

[](#properties-injection)

If your class use properties that are at meant to be added to the final array of attributes, you can inject them using the `injectProperties` method. Say you have a `Link` class that has an `url` property, you can overwrite the method like this, and the `$this->url` will get added in the `href` attribute :

```
protected function injectProperties()
{
  return array(
    'href' => $this->url,
  );
}
```

Or if the property bears the property's name you can simply add it to the array of automatically injected properties :

```
protected $injectedProperties = array('href', 'title');

// Will be added as href="#foo"
protected $href = '#foo';

// Will be added as title="title"
protected $title = 'title';

```

### Altering a precreated tree

[](#altering-a-precreated-tree)

HtmlObject allows to use the `open` and `close` to open tags but when your tag has children you sometimes want to open the tree at a particular point to inject data at runtime, you can do it like this :

```
$mediaObject = Element::div([
  'title' => Element::h2('John Doe'),
  'body'  => Element::div(),
]);

echo $mediaObject->openOn('body').'My name is John Doe'.$mediaObject->close();
```

```

  John Doe
  My name is John Doe

```

### Configuration

[](#configuration)

You can change whether to follow xHMTL or HTML5 specification by doing the following :

```
Tag::$config['doctype'] = '{xhtml|html}';
```

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 84.4% 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 ~273 days

Recently: every ~525 days

Total

14

Last Release

1195d ago

Major Versions

0.1.0 → 1.1.02013-11-05

### Community

Maintainers

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

---

Top Contributors

[![Anahkiasen](https://avatars.githubusercontent.com/u/1321596?v=4)](https://github.com/Anahkiasen "Anahkiasen (130 commits)")[![kylekatarnls](https://avatars.githubusercontent.com/u/5966783?v=4)](https://github.com/kylekatarnls "kylekatarnls (8 commits)")[![tortuetorche](https://avatars.githubusercontent.com/u/5038872?v=4)](https://github.com/tortuetorche "tortuetorche (3 commits)")[![patrickcarlohickman](https://avatars.githubusercontent.com/u/6036266?v=4)](https://github.com/patrickcarlohickman "patrickcarlohickman (2 commits)")[![mlocati](https://avatars.githubusercontent.com/u/928116?v=4)](https://github.com/mlocati "mlocati (2 commits)")[![armandomiani](https://avatars.githubusercontent.com/u/512214?v=4)](https://github.com/armandomiani "armandomiani (2 commits)")[![stayallive](https://avatars.githubusercontent.com/u/1090754?v=4)](https://github.com/stayallive "stayallive (1 commits)")[![weotch](https://avatars.githubusercontent.com/u/77567?v=4)](https://github.com/weotch "weotch (1 commits)")[![claar](https://avatars.githubusercontent.com/u/402855?v=4)](https://github.com/claar "claar (1 commits)")[![CWSpear](https://avatars.githubusercontent.com/u/495855?v=4)](https://github.com/CWSpear "CWSpear (1 commits)")[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![petercoles](https://avatars.githubusercontent.com/u/2947594?v=4)](https://github.com/petercoles "petercoles (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[spiral/core

IoC container, IoC scopes, factory, memory, configuration interfaces

188.2M126](/packages/spiral-core)

PHPackages © 2026

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