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

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

spatie/laravel-html
===================

A fluent html builder

3.13.0(2mo ago)8376.4M—6.1%10320MITPHPPHP ^8.2CI passing

Since Jan 24Pushed 2mo ago14 watchersCompare

[ Source](https://github.com/spatie/laravel-html)[ Packagist](https://packagist.org/packages/spatie/laravel-html)[ Docs](https://github.com/spatie/laravel-html)[ Fund](https://spatie.be/open-source/support-us)[ RSS](/packages/spatie-laravel-html/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (93)Used By (20)

 [   ![Logo for laravel-html](https://camo.githubusercontent.com/fe6956e41aac8f2cc2eb9074e39118549eb4efc0c733969067f8caddf37b61d9/68747470733a2f2f7370617469652e62652f7061636b616765732f6865616465722f6c61726176656c2d68746d6c2f68746d6c2f6c696768742e77656270)  ](https://spatie.be/open-source?utm_source=github&utm_medium=banner&utm_campaign=laravel-html)Painless HTML generation
========================

[](#painless-html-generation)

[![Latest Version on Packagist](https://camo.githubusercontent.com/09663685a7f9cb51d9c329d50747ec338a90767ad3f590f99b1ca3bf6d9c190b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d68746d6c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-html)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/5cb46e62d5dcb90797bcd6d69db46f0fb28fb9993ece0588cb939ae8bca24a84/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d68746d6c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-html)

This package helps you generate HTML using a clean, simple and easy to read API. All elements can be dynamically generated and put together. The HTML builder helps you generate dynamically assigned form elements based on your selected model, the session or a default value.

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/dba65b1812a7338b52f692fd847cb6ea0faa19878c57ebb0ee1a4482408c4a15/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d68746d6c2e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-html)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Postcardware
------------

[](#postcardware)

You're free to use this package (it's [MIT-licensed](LICENSE.md)), but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

All postcards are published [on our website](https://spatie.be/en/opensource/postcards).

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

[](#installation)

You can install the package via composer:

```
composer require spatie/laravel-html
```

And optionally register an alias for the facade.

```
// config/app.php
'aliases' => [
    ...
    'Html' => Spatie\Html\Facades\Html::class,
];
```

Usage
-----

[](#usage)

### Concepts

[](#concepts)

Elements—classes under the `Spatie\Html\Elements` namespace—are generally created via a `Spatie\Html\Html` builder instance.

```
html()->span()->text('Hello world!');
```

Element attributes and contents are modified via with fluent methods which return a new instance. This means element instances are immutable.

```
$icon = html()->span()->class('fa');

$icon->class('fa-eye'); // ''
$icon->class('fa-eye-slash'); // ''
```

Element classes don't have any knowledge of the outside world. Any coupling to other concepts, like requests and sessions, should happen in the builder class, not on the element classes.

By convention, we assume that builder methods will modify values to our advantage (like pulling old values from the session on a failed form request), and element methods will be deterministic.

```
// This will try to resolve an initial value, and fall back to 'hello@example.com'
$email = html()->email('email', 'hello@example.com');

// This will always have 'hello@example.com' as it's value
$email = html()->email('email')->value('hello@example.com');
```

Upgrading
---------

[](#upgrading)

### From v1 to v2

[](#from-v1-to-v2)

Version 2 was created because the typehints in version 1 was holding the package back in some cases (like multiple select which requires an array of values instead of a string which was assumed).

Luckily, bumping the version number in `composer.json` and running `composer update` should be non-breaking. Here are some caveats to look out for:

- The package now ships with a `html()` function by default, which returns an instance of the `Html` builder class. If you've defined your own method, you'll need to remove it.
- Various type hints have been removed throughout the package, if you've extended a class to override its methods, you'll need to update them accordingly (everything still behaves the same!)

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you've found a bug regarding security please mail  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Sebastian De Deyne](https://github.com/sebastiandedeyne)
- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

About Spatie
------------

[](#about-spatie)

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

76

—

ExcellentBetter than 100% of packages

Maintenance83

Actively maintained with recent releases

Popularity69

Solid adoption and visibility

Community46

Growing community involvement

Maturity92

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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

Recently: every ~84 days

Total

91

Last Release

86d ago

Major Versions

0.2.3 → 1.0.02017-03-31

1.5.0 → 2.0.02017-06-13

v1.x-dev → 2.22.12019-07-16

2.30.0 → 3.0.02021-11-17

v2.x-dev → 3.1.02022-01-14

PHP version history (6 changes)0.1.0PHP ^7.1

2.0.0PHP ^7.0

2.25.0PHP ^7.2

2.28.1PHP ^8.0|^7.2

3.0.0PHP ^8.0

3.6.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (187 commits)")[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (149 commits)")[![alexmanase](https://avatars.githubusercontent.com/u/10696975?v=4)](https://github.com/alexmanase "alexmanase (48 commits)")[![flyingluscas](https://avatars.githubusercontent.com/u/6232791?v=4)](https://github.com/flyingluscas "flyingluscas (10 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (8 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (8 commits)")[![miken32](https://avatars.githubusercontent.com/u/1329102?v=4)](https://github.com/miken32 "miken32 (8 commits)")[![rickselby](https://avatars.githubusercontent.com/u/1564517?v=4)](https://github.com/rickselby "rickselby (7 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (6 commits)")[![bskl](https://avatars.githubusercontent.com/u/9579731?v=4)](https://github.com/bskl "bskl (6 commits)")[![raveren](https://avatars.githubusercontent.com/u/364220?v=4)](https://github.com/raveren "raveren (6 commits)")[![CasperBE](https://avatars.githubusercontent.com/u/22048227?v=4)](https://github.com/CasperBE "CasperBE (5 commits)")[![azamtav](https://avatars.githubusercontent.com/u/2217592?v=4)](https://github.com/azamtav "azamtav (5 commits)")[![billmn](https://avatars.githubusercontent.com/u/779534?v=4)](https://github.com/billmn "billmn (5 commits)")[![fdrobnic](https://avatars.githubusercontent.com/u/35068993?v=4)](https://github.com/fdrobnic "fdrobnic (5 commits)")[![copernitim](https://avatars.githubusercontent.com/u/166406461?v=4)](https://github.com/copernitim "copernitim (4 commits)")[![francoism90](https://avatars.githubusercontent.com/u/5028905?v=4)](https://github.com/francoism90 "francoism90 (4 commits)")[![wesleyhf](https://avatars.githubusercontent.com/u/2936121?v=4)](https://github.com/wesleyhf "wesleyhf (3 commits)")[![jimirobaer](https://avatars.githubusercontent.com/u/8984769?v=4)](https://github.com/jimirobaer "jimirobaer (3 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (3 commits)")

---

Tags

formgenerationhtmllaravelphpspatiehtml

###  Code Quality

TestsPest

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-enum

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-feed

Generate rss feeds

9743.6M28](/packages/spatie-laravel-feed)[spatie/laravel-referer

Keep a visitor's original referer in session

532797.4k6](/packages/spatie-laravel-referer)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[yajra/laravel-datatables-editor

Laravel DataTables Editor plugin for Laravel 5.5+.

1186.1M2](/packages/yajra-laravel-datatables-editor)

PHPackages © 2026

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