Need help with html-object?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

128 Stars 18 Forks 146 Commits 4 Opened issues


A set of classes to create and manipulate HTML objects abstractions

Services available


Need anything else?

Contributors list


Build Status Latest Stable Version Total Downloads Scrutinizer Quality Score Code Coverage Support via Gittip

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

Static calls to the classes

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


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

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

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

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') //


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


$image = Image::create('img.jpg')->alt('foo'); // 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 folder.

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

method. Say you have a
class that has an
property, you can overwrite the method like this, and the
will get added in the
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

HtmlObject allows to use the

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


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

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

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.