An open API service indexing awesome lists of open source software.

https://github.com/ui-awesome/html

UI Awesome HTML code generator for PHP.
https://github.com/ui-awesome/html

code-generator html php ui-awesome

Last synced: 27 days ago
JSON representation

UI Awesome HTML code generator for PHP.

Awesome Lists containing this project

README

          



UI Awesome

Html





PHPUnit


Mutation Testing


PHPStan


A fluent, immutable PHP library for generating HTML elements with typed attribute helpers.

Safe by default content encoding, raw HTML when needed, and standards-compliant rendering.

## Features


Feature Overview

### Installation

```bash
composer require ui-awesome/html:^0.4
```

### Quick start

This package provides immutable, fluent wrapper classes for common HTML elements.

It supports safe content encoding via `content()`, raw HTML via `html()`, and composition using element instances.

#### Document skeleton + composition + immutability

```php
use UIAwesome\Html\Flow\{Div, Main, P};
use UIAwesome\Html\Heading\H1;
use UIAwesome\Html\Metadata\{Link, Meta, Title};
use UIAwesome\Html\Palpable\A;
use UIAwesome\Html\Root\{Body, Head, Html};

$baseLink = A::tag()->class('nav-link');

echo Html::tag()
->lang('en')
->html(
Head::tag()->html(
Meta::tag()->charset('utf-8'),
Meta::tag()->name('viewport')->content('width=device-width, initial-scale=1'),
Title::tag()->content('UI Awesome HTML'),
Link::tag()->rel('stylesheet')->href('/assets/app.css'),
),
Body::tag()->class('app')->html(
Main::tag()->class('container')->html(
H1::tag()->content('UI Awesome HTML'),
P::tag()->content('Build HTML with a fluent, immutable API.'),
Div::tag()->class('nav')->html(
$baseLink->href('/docs')->content('Documentation'),
$baseLink->href('/github')->content('GitHub'),
),
),
),
)
->render();
```

#### Safe content vs raw HTML

```php
use UIAwesome\Html\Flow\Div;

echo Div::tag()->content('encoded')->render();
//

<strong>encoded</strong>

echo Div::tag()->html('raw')->render();
//


// raw
//

```

#### Powerful list composition

Create ordered lists, unordered lists, and description lists with a fluent API.

```php
use UIAwesome\Html\List\{Dl, Ol, Ul};

// Unordered list with items
$features = Ul::tag()
->class('feature-list')
->items(
'Immutable by design',
'Type-safe attributes',
'Fluent API',
'Standards-compliant',
);

// Ordered list with custom start and nested items
$steps = Ol::tag()
->class('steps')
->start(1)
->reversed(false)
->li('Install with Composer', 1)
->li('Create HTML elements', 2)
->li('Render to string', 3);

// Description list for metadata or glossaries
$metadata = Dl::tag()
->class('metadata-list')
->dt('Package')
->dd('ui-awesome/html')
->dt('Version')
->dd('0.4.0')
->dt('License')
->dd('BSD-3-Clause');

// Render all lists
$html = $features->render() . PHP_EOL . $steps->render() . PHP_EOL . $metadata->render();
```

## Documentation

For detailed testing and quality workflows.

- [Testing Guide](docs/testing.md)

## Package information

[![PHP](https://img.shields.io/badge/%3E%3D8.3-777BB4.svg?style=for-the-badge&logo=php&logoColor=white)](https://www.php.net/releases/8.3/en.php)
[![Latest Stable Version](https://img.shields.io/packagist/v/ui-awesome/html.svg?style=for-the-badge&logo=packagist&logoColor=white&label=Stable)](https://packagist.org/packages/ui-awesome/html)
[![Total Downloads](https://img.shields.io/packagist/dt/ui-awesome/html.svg?style=for-the-badge&logo=composer&logoColor=white&label=Downloads)](https://packagist.org/packages/ui-awesome/html)

## Quality code

[![Codecov](https://img.shields.io/codecov/c/github/ui-awesome/html.svg?style=for-the-badge&logo=codecov&logoColor=white&label=Coverage)](https://codecov.io/github/ui-awesome/html)
[![PHPStan Level Max](https://img.shields.io/badge/PHPStan-Level%20Max-4F5D95.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/ui-awesome/html/actions/workflows/static.yml)
[![Super-Linter](https://img.shields.io/github/actions/workflow/status/ui-awesome/html/linter.yml?style=for-the-badge&label=Super-Linter&logo=github)](https://github.com/ui-awesome/html/actions/workflows/linter.yml)
[![StyleCI](https://img.shields.io/badge/StyleCI-Passed-44CC11.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.styleci.io/repos/776094320?branch=main)

## Our social networks

[![Follow on X](https://img.shields.io/badge/-Follow%20on%20X-1DA1F2.svg?style=for-the-badge&logo=x&logoColor=white&labelColor=000000)](https://x.com/Terabytesoftw)

## License

[![License](https://img.shields.io/badge/License-BSD--3--Clause-brightgreen.svg?style=for-the-badge&logo=opensourceinitiative&logoColor=white&labelColor=555555)](LICENSE)