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

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

lnear/html
==========

Utility functions for rendering html

1.1.3(1y ago)25755↓50%1[2 issues](https://github.com/lnear-dev/html/issues)MITPHPPHP ^8.0

Since Jun 18Pushed 1y agoCompare

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

READMEChangelog (5)Dependencies (2)Versions (6)Used By (0)

lnear/html: A PHP Library for Generating HTML Elements
======================================================

[](#lnearhtml-a-php-library-for-generating-html-elements)

This library provides a collection of functions for generating HTML elements and their attributes based on the [HTML Living Standard](https://html.spec.whatwg.org/multipage/indices.html).

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

[](#installation)

To install the library, use the following command:

```
composer require lnear/html
```

Usage
-----

[](#usage)

The library provides functions named after HTML elements, which accept attributes as named arguments. There are two namespaces available: `html` and `html\strict`.

- **`html\strict` Namespace:** Only allows attributes that are valid for the element according to the HTML Living Standard.
- **`html` Namespace:** More permissive, allowing any attribute to be passed to the function. Custom attribute names should be in camelCase.

### Examples

[](#examples)

```
// Using the strict namespace
html\strict\a(href: 'https://example.com', dataFoo: 'bar'); // Throws an InvalidArgumentException

// Using the permissive namespace
html\a(href: 'https://example.com', dataFoo: 'bar'); //
```

Other than the attribute restrictions, the two namespaces function identically. The following examples use the `html` namespace, but you can use the `html\strict` namespace to enforce the HTML standard.

### `data-*` Attributes

[](#data--attributes)

To pass `data-*` attributes with the `html\strict` namespace, use the `dataset` attribute as an associative array with keys as the attribute names without the `data-` prefix.

```
use function html\strict\a;

echo a(href: 'https://example.com', dataset: ['fooBar' => 'baz']); //
echo a(href: 'https://example.com', dataset: ['fooBar' => 'baz', 'barFoo' => 'qux']); //
```

All functions return a `Stringable` class (`html\RenderResult`) of the HTML element they represent. The only exception is the `var` function, which is named `variable` to avoid conflicts with the reserved keyword `var`.

### Body Argument

[](#body-argument)

The `body` argument is present in all non-self-closing elements, used to add text or other elements inside the element.

```
use function html\div;

echo div(body: 'Hello, World!'); // Hello, World!
```

The `body` argument is also the first argument in these functions, so the argument name can be omitted.

```
use function html\div;

echo div('Hello, World!'); // Hello, World!
```

### Nested Elements

[](#nested-elements)

More complex elements can be created by nesting functions, with the `body` argument as an array of elements.

```
use function html\{div, a, p};

echo div(
    class: 'container',
    body: [
        a('Click me!', href: 'https://example.com', target: '_blank', rel: 'noopener noreferrer'),
        p('This is a paragraph.')
    ]
);

// Click me!This is a paragraph.
```

Encoding
--------

[](#encoding)

The `html\RenderResult` class implements the `Stringable` interface, allowing its use in any context where a string is expected. It can also be used to bypass HTML encoding of a string.

```
use function html\{div, RenderResult};

$unsafe = 'alert("XSS")';

echo div(body: $unsafe); // Default encoding: &lt;script&gt;alert(&quot;XSS&quot;)&lt;/script&gt;

$safe = RenderResult::wrap($unsafe); // Explicit encoding

echo div(body: $safe); // No double encoding: &lt;script&gt;alert(&quot;XSS&quot;)&lt;/script&gt;

$byPass = RenderResult::encoded($unsafe); // String already encoded

echo div(body: $byPass); // alert("XSS")

// Or use the bypass helper function
use function html\bypass;
echo div(body: bypass($unsafe)); // alert("XSS")
```

Elements
========

[](#elements)

All elements share the following global attributes:

Attribute`accesskey``autocapitalize``class``contenteditable``contextmenu``dir``draggable``dropzone``hidden``id``itemid``itemprop``itemref``itemscope``itemtype``lang``spellcheck``style``tabindex``title``translate`The following elements only have the global attributes:

Tag`abbr``address``article``aside``b``bdi``bdo``br``caption``cite``code``datalist``dd``dfn``div``dl``dt``em``figcaption``figure``footer``h1``h2``h3``h4``h5``h6``head``header``hgroup``hr``i``kbd``legend``main``mark``math``menu``nav``noscript``p``picture``pre``rp``rt``ruby``s``samp``search``section``small``span``strong``sub``summary``sup``svg``table``tbody``tfoot``thead``title``tr``u``ul``var``wbr`The following elements have additional attributes:

TagAttributes`a`href, target, download, ping, rel, hreflang, type, referrerpolicy`area`alt, coords, shape, href, target, download, ping, rel, referrerpolicy`audio`src, crossorigin, preload, autoplay, loop, muted, controls`base`href, target`blockquote`cite`body`onafterprint, onbeforeprint, onbeforeunload, onhashchange, onlanguagechange, onmessage, onmessageerror, onoffline, ononline, onpageswap, onpagehide, onpagereveal, onpageshow, onpopstate, onrejectionhandled, onstorage, onunhandledrejection, onunload`button`disabled, form, formaction, formenctype, formmethod, formnovalidate, formtarget, name, popovertarget, popovertargetaction, type, value`canvas`width, height`col`span`colgroup`span`data`value`del`cite, datetime`details`name, open`dialog`open`embed`src, type, width, height`fieldset`disabled, form, name`form`accept-charset, action, autocomplete, enctype, method, name, novalidate, rel, target`html`manifest`iframe`src, srcdoc, name, sandbox, allow, allowfullscreen, width, height, referrerpolicy, loading`img`alt, src, srcset, sizes, crossorigin, usemap, ismap, width, height, referrerpolicy, decoding, loading, fetchpriority`input`accept, alt, autocomplete, checked, dirname, disabled, form, formaction, formenctype, formmethod, formnovalidate, formtarget, height, list, max, maxlength, min, minlength, multiple, name, pattern, placeholder, popovertarget, popovertargetaction, readonly, required, size, src, step, type, value, width`ins`cite, datetime`label`for`li`value`link`href, crossorigin, rel, as, media, hreflang, type, sizes, imagesrcset, imagesizes, referrerpolicy, integrity, blocking, color, disabled, fetchpriority`map`name`meta`name, http-equiv, content, charset, media`meter`value, min, max, low, high, optimum`object`data, type, name, form, width, height`ol`reversed, start, type`optgroup`disabled, label`option`disabled, label, selected, value`output`for, form, name`progress`value, max`q`cite`script`src, type, nomodule, async, defer, crossorigin, integrity, referrerpolicy, blocking, fetchpriority`select`autocomplete, disabled, form, multiple, name, required, size`slot`name`source`type, media, src, srcset, sizes, width, height`style`media, blocking`td`colspan, rowspan, headers`template`shadowrootmode, shadowrootdelegatesfocus, shadowrootclonable, shadowrootserializable`textarea`autocomplete, cols, dirname, disabled, form, maxlength, minlength, name, placeholder, readonly, required, rows, wrap`th`colspan, rowspan, headers, scope, abbr`time`datetime`track`default, kind, label, src, srclang`video`src, crossorigin, poster, preload, autoplay, playsinline, loop, muted, controls, width, height

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

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

Total

5

Last Release

669d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/27f2f0c5d47c596274bba2fb2d20f5a02854b8b3f06557d98ada60bd3f46ebba?d=identicon)[lnear](/maintainers/lnear)

---

Top Contributors

[![oplanre](https://avatars.githubusercontent.com/u/113967437?v=4)](https://github.com/oplanre "oplanre (18 commits)")[![andywebb-net](https://avatars.githubusercontent.com/u/75171720?v=4)](https://github.com/andywebb-net "andywebb-net (2 commits)")

###  Code Quality

TestsPest

### Embed Badge

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

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

###  Alternatives

[umpirsky/transliterator

Transliterator is a PHP library for text transliteration.

63174.9k1](/packages/umpirsky-transliterator)

PHPackages © 2026

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