Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Html Laravel Package

yiisoft/html

Yii HTML is a PHP library for safe, dynamic server-side HTML generation. It provides classes for common HTML tags, a CustomTag builder, widgets like ButtonGroup/CheckboxList/RadioList, automatic content encoding with NoEncode, and an Html helper API.

View on GitHub
Deep Wiki
Context7

Handy library to generate HTML

Frequently asked questions about Html
How do I integrate yiisoft/html into a Laravel project?
Install via Composer with `composer require yiisoft/html`. Register the service provider in `config/app.php` or use facades like `Html::tag()` directly in Blade/Livewire. For Blade directives, create a custom helper or facade to bridge the package’s methods.
Does yiisoft/html support Laravel 10+ and PHP 8.1+?
Yes, the package is fully compatible with Laravel 10+ and PHP 8.1+. It enforces stricter type handling (e.g., `int`, `float`, `null` for tag content) and may require updates to dynamic HTML logic using older PHP versions.
What’s the breaking change with `$options` renamed to `$attributes`?
Methods like `addCssClass()` now use `$attributes` instead of `$options`. Update any custom helpers, Blade directives, or service providers using these methods. This improves clarity but requires code changes.
Can I use yiisoft/html with Livewire or Inertia.js?
Yes, the package works well with Livewire for dynamic components (e.g., `CheckboxList`, `RadioList`) and Inertia.js for server-rendered HTML. Stricter validation (e.g., required `CheckboxItem` properties) enhances robustness in these use cases.
How does yiisoft/html handle XSS prevention?
All tag content is auto-encoded by default. Use the `NoEncode` class for raw content (e.g., JavaScript). This aligns with Laravel’s security best practices for server-side HTML generation.
Are there alternatives to yiisoft/html for Laravel?
For Blade templates, consider Laravel’s built-in `Html::tag()` or packages like `spatie/html`. For component-based apps, `livewire/ui` or `filament/support` offer integrated solutions. yiisoft/html stands out for its widget support (e.g., `ButtonGroup`) and Yii’s legacy.
Will yiisoft/html work with Alpine.js or Vue/React?
The package is PHP-focused and lacks native JS framework integration. For Vue/React, use inline Blade templates or Laravel Mix/Vite for static HTML. Dynamic components should use Laravel’s frontend presets (e.g., `laravel-mix` with `vue-loader`).
How do I handle empty IDs in tags after the LogicException change?
Validate IDs before passing them to `Tag::id()`. For example, use `Html::tag('div', '', ['id' => $id ?? 'default-id'])` or throw a custom exception if IDs are critical. This change prevents runtime errors in production.
Does yiisoft/html support deterministic attribute sorting?
No, the package removed attribute sorting (Chg #234). If your project relies on consistent HTML output (e.g., for minification or testing), implement custom sorting logic or use a post-processing tool like `htmlmin`.
How can I test yiisoft/html in a Laravel project?
Test by generating tags in unit tests (e.g., `Html::tag('div', 'test')`) and asserting output with PHPUnit. Mock `Html` facades or use `partial()` in Blade tests. Validate edge cases like encoding, empty IDs, and widget rendering (e.g., `CheckboxList`).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope