PHPackages                             nicksdot/blade-html-attributes - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. nicksdot/blade-html-attributes

ActiveLibrary[Templating &amp; Views](/categories/templating)

nicksdot/blade-html-attributes
==============================

Laravel Blade directives for conditionally rendering HTML attributes

0.1.0(7mo ago)11[1 PRs](https://github.com/NickSdot/blade-html-attributes/pulls)MITPHPPHP ^8.1

Since Oct 18Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/NickSdot/blade-html-attributes)[ Packagist](https://packagist.org/packages/nicksdot/blade-html-attributes)[ RSS](/packages/nicksdot-blade-html-attributes/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (10)Versions (3)Used By (0)

Blade HTML Attributes
=====================

[](#blade-html-attributes)

A Laravel package that provides Blade directives for conditionally rendering HTML attributes.

Installation
------------

[](#installation)

```
composer require nicksdot/blade-html-attributes
```

The package will auto-register the service provider.

Available Directives
--------------------

[](#available-directives)

### Behaviour Matrix

[](#behaviour-matrix)

**Note:** Rows in **bold** show special operator `=` &amp; `!` behaviour.

Value`@attr``@data``@aria``@flag``('foo', "bar")``foo="bar"``data-foo="bar"``aria-foo="bar"``foo``('foo', "1")``foo="1"``data-foo="1"``aria-foo="1"``foo``('foo', 1)``foo="1"``data-foo="1"``aria-foo="1"``foo``('foo', true)``foo``data-foo``aria-foo="true"``foo`**`('foo=', true)`****`foo="true"`****`data-foo="true"`**`aria-foo="true"``foo``('foo', false)`*(nothing)**(nothing)*`aria-foo="false"`*(nothing)***`('foo=', false)`****`foo="false"`****`data-foo="false"`**`aria-foo="false"`*(nothing)***`('!foo', false)`***(throws)**(throws)****(nothing)****(throws)*`('foo', "0")``foo="0"``data-foo="0"``aria-foo="0"`*(nothing)*`('foo', 0)``foo="0"``data-foo="0"``aria-foo="0"`*(nothing)*`('foo', '')`*(nothing)**(nothing)**(nothing)**(nothing)***`('foo=', '')`****`foo=""`****`data-foo=""`***(nothing)**(nothing)*`('foo', '   ')`*(nothing)**(nothing)**(nothing)**(nothing)***`('foo=', '   ')`****`foo="   "`****`data-foo="   "`***(nothing)**(nothing)*`('foo', null)`*(nothing)**(nothing)**(nothing)**(nothing)***Gotchas:**

- `@attr` and `@data` allow the `=` suffix (e.g., `@attr('foo=', $value)`) to force values (always render with `="value"`, even for booleans and empty strings)
- `@aria` allows the `!` prefix (e.g., `@aria('!foo', $value)`) to negate false values for removing attribute entirely.

### Descriptions

[](#descriptions)

- **`@attr`**: By default, `true` renders as a boolean flag (attribute name only), and `false`/empty/whitespace-only/null render nothing. With the force-value operator (`=` suffix like `'foo='`), always renders with values including`"true"`, `"false"`, and empty strings.
- **`@data`**: Same as `@attr` but automatically prefixes attribute names with `data-`.
- **`@aria`**: By default, renders all values including `"true"` and `"false"` (never as boolean flags). Never renders empty or whitespace-only strings. With the negation operator (`!` prefix like `'! foo'`), `false` the attribute is completely removed instead of rendering as `"false"`.
- **`@flag`**: Outputs just the attribute name without a value (boolean flag), for truthy values only. Follows HTML spec for boolean attributes like `disabled`, `checked`, `required` or `data-foo`.

Examples
--------

[](#examples)

### `@attr` Directive

[](#attr-directive)

```
{{-- Before / After --}}
title) title="{{ $link->title }} @endif" @if($link->rel) rel="{{ $link->rel }} @endif">
title) @attr('rel', $link->rel)>

{{-- Before / After --}}

{{-- Before / After --}}

{{-- Force rendering booleans as string value --}}

    Edit me (renders as `contenteditable="true"`)

```

### `@data` Directive

[](#data-directive)

```
{{-- Before / After --}}

{{-- Before / After --}}

{{-- Force rendering booleans as string value --}}

    Click (renders as `data-toggle="true"`)

```

### `@aria` Directive

[](#aria-directive)

```
{{-- Before / After --}}

{{-- Before / After --}}

{{-- Before / After --}}

```

### `@flag` Directive

[](#flag-directive)

```
{{-- Before --}}
Submit

{{-- After --}}
Submit

{{-- Multiple flag attributes --}}

```

Requirements
------------

[](#requirements)

- PHP 8.1+
- Laravel 10.0+

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT licence](LICENCE.md).

Credits
-------

[](#credits)

- [Nick](https://github.com/nicksdot)

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance66

Regular maintenance activity

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

213d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3162c42d78f1ecd8d4d97f372566c6ad7728306b9743a5861c61650f24c8b3fc?d=identicon)[NickSdot](/maintainers/NickSdot)

---

Top Contributors

[![NickSdot](https://avatars.githubusercontent.com/u/32384907?v=4)](https://github.com/NickSdot "NickSdot (16 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/nicksdot-blade-html-attributes/health.svg)

```
[![Health](https://phpackages.com/badges/nicksdot-blade-html-attributes/health.svg)](https://phpackages.com/packages/nicksdot-blade-html-attributes)
```

###  Alternatives

[rcrowe/twigbridge

Adds the power of Twig to Laravel

9105.9M50](/packages/rcrowe-twigbridge)[tightenco/jigsaw

Simple static sites with Laravel's Blade.

2.2k438.5k29](/packages/tightenco-jigsaw)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[moonshine/moonshine

Laravel administration panel

1.3k217.1k59](/packages/moonshine-moonshine)[livewire/blaze

A tool for optimizing Blade component performance by folding them into parent templates

688221.3k17](/packages/livewire-blaze)[tallstackui/tallstackui

TallStackUI is a powerful suite of Blade components that elevate your workflow of Livewire applications.

703141.0k7](/packages/tallstackui-tallstackui)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
