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

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

marwanalsoltany/php-html
========================

A fluent interface for creating HTML using PHP.

v1.0.0(3y ago)17MITPHPPHP &gt;=7.4

Since Aug 17Pushed 3y ago1 watchersCompare

[ Source](https://github.com/MarwanAlsoltany/php-html)[ Packagist](https://packagist.org/packages/marwanalsoltany/php-html)[ Docs](https://github.com/MarwanAlsoltany/php-html#readme)[ Fund](https://ko-fi.com/marwanalsoltany)[ RSS](/packages/marwanalsoltany-php-html/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

PHP-HTML
========

[](#php-html)

A fluent interface for creating HTML using PHP.

[![PHP Version](https://camo.githubusercontent.com/7d770db38bc264d6f6edd39b48046edd50fedd1d436e52f3cd6e79a80da4c44d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533453d382e302d79656c6c6f773f7374796c653d666c6174266c6f676f3d706870)](https://github.com/MarwanAlsoltany/php-html/search?l=php)[![Latest Version on Packagist](https://camo.githubusercontent.com/2cc44c20b72f2112d3bf2345d25646498615e6573dfeb9c1d4b2b46e460fedf9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f4d617277616e416c736f6c74616e792f7068702d68746d6c2e7376673f7374796c653d666c6174266c6f676f3d7061636b6167697374)](https://packagist.org/packages/MarwanAlsoltany/php-html)[![Total Downloads](https://camo.githubusercontent.com/f16ed1f04754e8172b433f427fb786b70f59d8019a4710dd2cb9b416d52539ac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f4d617277616e416c736f6c74616e792f7068702d68746d6c2e7376673f7374796c653d666c6174266c6f676f3d7061636b6167697374)](https://packagist.org/packages/MarwanAlsoltany/php-html/stats)[![License](https://camo.githubusercontent.com/8e5bdeb25cec99ef8c5345207c75dcab39dc539399bd321e9f4e73396b581686/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d7265642e7376673f7374796c653d666c6174266c6f676f3d676974687562)](./LICENSE)[![Maintenance](https://camo.githubusercontent.com/068fd45ce0e3bc55bc753945ee21519d011ea319c92d060f0a62eac52e76f54e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d61696e7461696e65642d7965732d6f72616e67652e7376673f7374796c653d666c6174266c6f676f3d676974687562)](https://github.com/MarwanAlsoltany/php-html/graphs/commit-activity)[![Documentation](https://camo.githubusercontent.com/98064cac7c14df45aba524dcdfa27561a318a5c8d31b5316ae0aa8f6187f15e7/68747470733a2f2f696d672e736869656c64732e696f2f776562736974652d75702d646f776e2d626c75652d7265642f687474702f4d617277616e416c736f6c74616e792e6769746875622e696f2f7068702d68746d6c2e737667)](https://MarwanAlsoltany.github.io/php-html)
[![GitHub Continuous Integration](https://github.com/MarwanAlsoltany/php-html/actions/workflows/ci.yml/badge.svg)](https://github.com/MarwanAlsoltany/php-html/actions)[![GitHub Continuous Deployment](https://github.com/MarwanAlsoltany/php-html/actions/workflows/cd.yml/badge.svg)](https://github.com/MarwanAlsoltany/php-html/actions)[![Codecov](https://camo.githubusercontent.com/7983b52a73147017babc76c2f7a2ba4dd1d517d0fe381bceed48ad98773746dc/68747470733a2f2f636f6465636f762e696f2f67682f4d617277616e416c736f6c74616e792f7068702d68746d6c2f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d464e55335a4e4348544e)](https://codecov.io/gh/MarwanAlsoltany/php-html)

[![Open in Visual Studio Code](https://camo.githubusercontent.com/821a60ac3a234e9dfc8569606ae5c68c932b15215af5b0a5e73715e3aae8a78e/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6f676f3d76697375616c73747564696f636f6465266c6162656c3d266d6573736167653d4f70656e253230696e2532305653253230436f6465266c6162656c436f6c6f723d32633263333226636f6c6f723d303037616363266c6f676f436f6c6f723d303037616363)](https://open.vscode.dev/MarwanAlsoltany/php-html)

[![Tweet](https://camo.githubusercontent.com/cb820a0ecc9645168e33b03925d7f14691262ddbaeaf66a0a91697803d0cba2d/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f75726c2f687474702f736869656c64732e696f2e7376673f7374796c653d736f6369616c)](https://twitter.com/intent/tweet?url=https%3A%2F%2Fgithub.com%2FMarwanAlsoltany%2Fphp-html&text=Check%20out%MarwanAlsoltany%2Fphp-html%20on%20GitHub%21%20%23PHP) [![Star](https://camo.githubusercontent.com/a43f90165843289488a9297bae704f21b656cd559df9a50b948b102ab06272dd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f4d617277616e416c736f6c74616e792f7068702d68746d6c2e7376673f7374796c653d736f6369616c266c6162656c3d53746172)](https://github.com/MarwanAlsoltany/php-html/stargazers)

Table of Contents[About](#about)
[Installation](#installation)
[Examples](#examples)
[More](#more)
[Changelog](./CHANGELOG.md)

If you like this project and would like to support its development, giving it a ⭐ would be appreciated!

---

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

[](#installation)

#### Using Composer:

[](#using-composer)

Install PHP-HTML through Composer using:

```
composer require marwanalsoltany/php-html
```

---

Why Does This Exist?
--------------------

[](#why-does-this-exist)

Why not?

This is something that I exclusively created for myself. The real reason why this exist is, I really hate writing HTML within PHP code (especially in classes). If it is more than one line and it is not a template, it looks really ugly and it doesn't feel like it belongs to the code although it does. This package provides a fluent interface for the sole reason of not writing raw HTML in PHP. It also indents and validates the generated HTML and provides IDE-IntelliSense for all HTML elements to make it as easy as it gets.

---

Examples
--------

[](#examples)

Here is an example of how it works:

```
// on the fly
echo MAKS\PhpHtml\HTML::div('This is a div!', ['class' => 'container']);

// the whole deal
echo (new \MAKS\PhpHtml\HTML())
    ->element('h1', 'HTML Forms', ['class' => 'title'])
    ->open('form', ['method' => 'POST'])
        ->comment('SIMPLE FORM')
        ->h2('Example', ['class' => 'subtitle'])
        ->p('This is an example form.')
        ->br()
        ->if(isset($variable))->div('$variable is set')
        ->open('fieldset')
            ->legend('Form 1', ['style' => 'color: #333;'])
            ->label('Message: ', ['class' => 'text'])
            ->input(['type' => 'text', 'required'])
            ->entity('nbsp')
            ->input(['type' => 'submit', 'value' => 'Submit'])
        ->close()
        ->open('ul', ['class' => 'errors'])
            ->do(function () {
                $errors = ['Error 1', 'Error 2', 'Error 3'];

                foreach ($errors as $error) {
                    $this->li($error);
                }
            })
        ->close()
    ->close()
->render();
```

The generated HTML would look like this:

```

This is a div!

HTML Forms

    Example
    This is an example form.

        Form 1
        Message:

        &nbsp;

        Error 1
        Error 2
        Error 3

```

---

License
-------

[](#license)

PHP-HTML is an open-source project licensed under the [**MIT**](./LICENSE) license.
Copyright (c) 2022 Marwan Al-Soltany. All rights reserved.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1370d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7969982?v=4)[Marwan Al-Soltany](/maintainers/MarwanAlsoltany)[@MarwanAlsoltany](https://github.com/MarwanAlsoltany)

---

Top Contributors

[![MarwanAlsoltany](https://avatars.githubusercontent.com/u/7969982?v=4)](https://github.com/MarwanAlsoltany "MarwanAlsoltany (12 commits)")

---

Tags

htmllibraryphpphplibraryhtmlfluentphp-html

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[froala/wysiwyg-editor-php-sdk

PHP SDK for Froala WYSIWYG Editor

431.5M](/packages/froala-wysiwyg-editor-php-sdk)[phug/phug

Pug (ex-Jade) facade engine for PHP, HTML template engine structured by indentation

67292.2k13](/packages/phug-phug)[epic-64/elem

A fluent, type-safe PHP library for building HTML documents using the DOM

272.9k](/packages/epic-64-elem)

PHPackages © 2026

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