Introduction | laravel-html | Spatie

 SPATIE

  Laravel HTML
===============

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-html](https://spatie.be/docs/laravel-html/v2)  Introduction

 Version   v3   v2   v1

 Other versions for crawler [v3](https://spatie.be/docs/laravel-html/v3) [v2](https://spatie.be/docs/laravel-html/v2) [v1](https://spatie.be/docs/laravel-html/v1)

- [ Introduction ](https://spatie.be/docs/laravel-html/v2/introduction)
- [ Postcardware ](https://spatie.be/docs/laravel-html/v2/postcardware)
- [ Installation &amp; setup in Laravel ](https://spatie.be/docs/laravel-html/v2/installation-setup)
- [ Upgrading ](https://spatie.be/docs/laravel-html/v2/upgrading)
- [ Questions and issues ](https://spatie.be/docs/laravel-html/v2/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-html/v2/changelog)

General usage
-------------

- [ Core concepts ](https://spatie.be/docs/laravel-html/v2/general-usage/core-concepts)
- [ HTML builder ](https://spatie.be/docs/laravel-html/v2/general-usage/html-builder)
- [ Element classes ](https://spatie.be/docs/laravel-html/v2/general-usage/element-classes)
- [ Element methods ](https://spatie.be/docs/laravel-html/v2/general-usage/element-methods)
- [ The class() helper ](https://spatie.be/docs/laravel-html/v2/general-usage/the-class-helper)

      You are viewing the documentation for **an older version** of this package. You can check the version you are using with the following command:

 `                                    composer show spatie/laravel-html                                                                                                                                                                                                                                    `

 Laravel HTML
==============

 [    Repository ](https://github.com/spatie/laravel-html)

    6,463,654

    827

Introduction
------------

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.

### Generating elements

For example creating a new `span` element with a class is super easy with the [fluent methods for elements](/laravel-html/v1/general-usage/element-methods):

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

### Building forms

Here's a quick example that builds a basic form with an e-mail input:

```
{{ html()->form('PUT', '/post')->open() }}

{{ html()->email('email')->placeholder('Your e-mail address') }}

{{ html()->form()->close() }}
```

The generated HTML will look like this:

```

```

Notice how the hidden `_method` and `_token` fields were automatically added and filled? You'll never forget to add `csrf_field()` again because now you simply wont have to anymore!

Another common use case might be to fill an input element based on the value that was previously submitted (using `$request->old()`). Worry no more, this has been taken care of as well. The above code will automatically fill in the `email` field if `$session->old('email')` exists. Amazing.

### Models in the HTML builder

The HTML builder can also generate elements based on a model:

```
{{ html()->model($user) }}

{{ html()->input('name') }}
```

The value of the `name` field will automatically be filled with the model's `name` property if available:

```

```

A "model" can be any object that implements `ArrayAccess` — anything from a complex Eloquent model to a plain array.
