PHPackages                             bpstr/elements-php - 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. [Templating &amp; Views](/categories/templating)
4. /
5. bpstr/elements-php

ActiveLibrary[Templating &amp; Views](/categories/templating)

bpstr/elements-php
==================

A simple PHP library to render HTML elements.

0291[1 issues](https://github.com/bpstr/elements-php/issues)[1 PRs](https://github.com/bpstr/elements-php/pulls)PHPCI failing

Since Nov 7Pushed 3mo agoCompare

[ Source](https://github.com/bpstr/elements-php)[ Packagist](https://packagist.org/packages/bpstr/elements-php)[ RSS](/packages/bpstr-elements-php/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (2)Used By (0)

elements-php
============

[](#elements-php)

Render HTML elements with PHP.

Inspired by chainable query structures, and jQuery DOM management.

With Elements-php it is possible to render an HTML element without writing a single line of HTML code.

Basic markup
------------

[](#basic-markup)

Create a simple Markup object with chainable methods. When turning it into a string, you will get a [standard markup](https://en.wikipedia.org/wiki/Markup_language).

```
$markup = Markup::create('document')->attr('created', date('Y-m-d');
$markup->content('title', Markup::create('title', 'Lorem ipsum.'));
echo $markup;
```

And the output will be:

```
Lorem ipsum.
```

Creating an element
-------------------

[](#creating-an-element)

The `Element` class extends `Markup` to provide more advenced features for rendering HTML.

```
$div = Element::create('p', 'Lorem ipsum', ['class' => 'lead']);

echo $div; // Lorem ipsum
```

The same result can be achieved with chainable methods:

```
echo Element::create('p')->appendContent('Lorem ipsum')->addClass('lead');

// OR

$div = new Element('p');
$div->appendContent('Lorem ipsum');
if (true) {
    $div->addClass('lead');
}

echo $div;
```

### Creating more advanced structures

[](#creating-more-advanced-structures)

It is possible to pass another element, or array of other elements as the second argument of `Element::create()` which makes it incredibly convinent to render advanced HTML structures *with pure PHP!*

```
echo Element::create('div', [
    new Heading('This is an H1 tag'),
    Element::create('ul', [
        Element::create('li', 'The first list item'),
        Element::create('li', 'The second item'),
    ]),
    new Image('image.jpg', 'Some Alt text')
])->addClass('container');
```

The example above will return the following HTML markup: **(minified!)**

```

    This is an H1 tag

        The first list item
        The second item

```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance54

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity26

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/37303771?v=4)[Fent Jani](/maintainers/bpstr)[@bpstr](https://github.com/bpstr)

---

Top Contributors

[![bpstr](https://avatars.githubusercontent.com/u/37303771?v=4)](https://github.com/bpstr "bpstr (1 commits)")

### Embed Badge

![Health badge](/badges/bpstr-elements-php/health.svg)

```
[![Health](https://phpackages.com/badges/bpstr-elements-php/health.svg)](https://phpackages.com/packages/bpstr-elements-php)
```

###  Alternatives

[mustache/mustache

A Mustache implementation in PHP.

3.3k44.6M291](/packages/mustache-mustache)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[nicmart/string-template

StringTemplate is a very simple string template engine for php. I've written it to have a thing like sprintf, but with named and nested substutions.

2101.7M30](/packages/nicmart-string-template)

PHPackages © 2026

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