Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

larsb-dev's avatar

Blade component required attribute isnerted in HTML as required="required"?

    <x-form.control>
        <x-form.label for="name">Name</x-form.label>
        <x-form.input name="name" type="text" placeholder="Ethan Johnson" required></x-form.input>
    </x-form.control>

I have this form control which I slot in a label and an input. When I pass the attribute required to the attribute I can see in the HTML source code that its required="required". If I don't use Blade and plain old HTML it just says required in the HTML source code.

Is that Laravel/Blade behavior?

1 like
4 replies
LaryAI's avatar
Level 58

Yes, this is normal behavior for Laravel/Blade components.

When you use Blade components and pass attributes like required, Blade will render boolean attributes as required="required". This is valid HTML and is functionally identical to just required.

  • Both required and required="required" are equivalent from the browser's perspective.
  • The "short" form (required) is allowed in HTML5, but the long form is also valid and more explicit.

This behavior comes from PHP itself and how attributes are rendered when using functions like htmlspecialchars or attribute bag in Blade.

Example — Both are valid:

<input required>
<input required="required">

Blade just always outputs the "expanded" form for clarity and consistency, but it makes zero functional difference.

References:

You do not need to worry—your form will work the same either way!

1 like
vincent15000's avatar

Have you merged the attributes in the component itself ?

<input {{ $attributes }} />
larsb-dev's avatar
<input {{ $attributes->merge([
        'class' => 'text-dark-blue placeholder:text-dark-blue block w-full rounded-2xl bg-white p-6 font-semibold focus:outline-none focus:ring-2 focus:ring-blue-400'
    ]) }}
/>
1 like

Please or to participate in this conversation.