# HTML Attribute

> A focused library for building and rendering structured HTML attributes

Package entry: `ui-awesome/html-attribute`. Requires PHP `^8.3`. Checked 2026-11-14. [View the entry in the package directory](</docs/packages/ui-awesome/html-attribute/index.md>)

## Features

![Feature Overview](https://raw.githubusercontent.com/ui-awesome/html-attribute/main/docs/svgs/features.svg)

**A focused library for building and rendering structured HTML attributes**

_Type-safe helpers and value objects to compose complex attribute structures (classes, data-attributes, ARIA, etc.)._

### Installation

```bash
composer require ui-awesome/html-attribute:^0.8
```

### Quick start

Compose reusable attribute APIs by combining the package traits with the immutable attribute mixin.

```php
<?php

declare(strict_types=1);

namespace App;

use UIAwesome\Html\Attribute\Global\{HasClass, HasData, HasId};
use UIAwesome\Html\Attribute\HasRel;
use UIAwesome\Html\Attribute\Values\Rel;
use UIAwesome\Html\Helper\Attributes;
use UIAwesome\Html\Mixin\HasAttributes;

final class LinkAttributes
{
    use HasAttributes;
    use HasClass;
    use HasData;
    use HasId;
    use HasRel;

    public function render(): string
    {
        return Attributes::render($this->getAttributes());
    }
}

$attributes = (new LinkAttributes())
    ->id('documentation')
    ->class('nav-link')
    ->class('is-active')
    ->rel(Rel::NOOPENER)
    ->addDataAttribute('tracking', 'docs');

echo '<a' . $attributes->render() . ' href="/docs">Documentation</a>';
// <a class="nav-link is-active" id="documentation" rel="noopener" data-tracking="docs" href="/docs">Documentation</a>
```

## Documentation

For detailed configuration options and advanced usage, see the [repository](https://github.com/ui-awesome/html-attribute):

- 🧪 [Testing Guide](https://github.com/ui-awesome/html-attribute/blob/main/docs/testing.md)

## AI assistance

AI agents: read the [documentation index](https://yii2-framework.github.io/docs/llms.txt) and fetch the Markdown version
of a page by appending `index.md` to its URL. The
[AI agents guide](https://github.com/yii2-framework/docs/blob/main/src/content/docs/project/ai-agents.md) covers skill installation, client setup and
verification.

- 🤖 [`ui-awesome-html-attribute` skill](https://github.com/ui-awesome/html-attribute): global, ARIA, `data-*`, event and element-specific attribute
  traits, and their value enums.

Match the installed package revision. If hosted documentation does not match or is unavailable, use the
[repository guides](#documentation), the installed skill source at `skills/ui-awesome-html-attribute/SKILL.md`, the source
PHPDoc and the [changelog](https://github.com/ui-awesome/html-attribute/blob/main/CHANGELOG.md). The package-specific AI guide is available in the repository after the pending
skill changes are published. This package is framework-independent and does not render HTML by itself; rendering comes
from `ui-awesome/html-helper`.

## Our social networks

[Follow on X](https://x.com/Terabytesoftw)
[Follow on Facebook](https://www.facebook.com/wilmer.arambula.9)

## License

[License](https://github.com/ui-awesome/html-attribute/blob/main/LICENSE)

## Package

- Source code and issues: [ui-awesome/html-attribute](https://github.com/ui-awesome/html-attribute). Star the repository if the package is useful to you.
- Composer package: [ui-awesome/html-attribute](https://packagist.org/packages/ui-awesome/html-attribute).
- Changelog: [CHANGELOG.md](https://github.com/ui-awesome/html-attribute/blob/main/CHANGELOG.md).