Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How do I pass additional HTML attributes to a Blade component


How do I pass additional HTML attributes to a Blade component


To pass additional HTML attributes to a Laravel Blade component, you can use the `$attributes` variable in your component's Blade template.

The `$attributes` variable contains all the attributes that were passed to the component but were not defined as props. You can render these attributes on the root element of your component using the `< $attributes >` directive.

For example, let's say you have a `` component with the following template:

html
<button {{ $attributes }}>
    {{ $slot }}
</button>

In your parent view, you can pass additional attributes to the component like this:

html
<x-button class="btn btn-primary" wire:click="doSomething">
    Click me
</x-button>

The `class` and `wire:click` attributes will be rendered on the `