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

Tools for dynamic server-side HTML generation: rich set of tag classes, custom tags, widgets (ButtonGroup, CheckboxList, RadioList), automatic HTML-encoding with NoEncode bypass, and an Html helper with static methods to build tags and widgets.

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.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views