A Laravel package that formats Blade templates and Livewire Single File Components. Similar to how Laravel Pint formats PHP — run a single command and your Blade files are clean.
Includes a VS Code extension for format-on-save.
Blade Formatter runs three formatters in sequence:
- PHP formatting — Formats the PHP section of Livewire SFCs using Laravel Pint
- Tailwind class sorting — Sorts Tailwind CSS classes using Prettier with prettier-plugin-tailwindcss (the official Tailwind Labs solution)
- Blade indentation — Auto-indents Blade templates with proper nesting for HTML tags, Blade directives (
@if/@foreach/@switch, etc.), and component tags (<x-*>,<flux:*>,<livewire:*>)
Each formatter can be enabled or disabled independently.
- HTML tags (including
<x-*>,<flux:*>,<livewire:*>components) - Blade directives (
@if/@endif,@foreach/@endforeach,@switch/@case, etc.) - Multi-line HTML tag attributes
- Alpine.js
x-dataand other multi-line attribute values with nested braces/brackets @props([...])and similar multi-line directive arguments
Content inside @verbatim and <pre> blocks is preserved exactly as-is.
- PHP 8.2+
- Laravel 12+
- Node.js (for Tailwind class sorting via Prettier)
Install the package via Composer:
composer require joelstein/blade-formatter --devFor Tailwind class sorting, install Prettier and the Tailwind plugin:
npm install -D prettier prettier-plugin-tailwindcssOptionally publish the config file:
php artisan vendor:publish --tag=blade-formatter-configFormat all Blade files:
vendor/bin/blade-formatOr via Artisan:
php artisan blade:formatFormat specific files or directories:
vendor/bin/blade-format resources/views/components
vendor/bin/blade-format resources/views/home.blade.phpCheck formatting without making changes (useful for CI):
vendor/bin/blade-format --testOnly format git-dirty files:
vendor/bin/blade-format --dirtyThe package includes a VS Code extension that formats Blade files on save.
-
Install the PHP package (see Installation above)
-
Build the VS Code extension:
cd vendor/joelstein/blade-formatter npm install npm run build -
Symlink the extension into VS Code:
ln -s vendor/joelstein/blade-formatter ~/.vscode/extensions/blade-formatter -
Reload VS Code
- Format on save — Blade files are automatically formatted when you save
- Manual format — Use the command palette:
Format Blade File - Language mode switching — Automatically switches between PHP and Blade language modes based on cursor position in Livewire SFCs, giving you proper intellisense in each section
All settings are under bladeFormatter.*:
| Setting | Type | Default | Description |
|---|---|---|---|
enable |
boolean | true |
Enable or disable the extension |
formatOnSave |
boolean | true |
Format Blade files on save |
enableLanguageSwitching |
boolean | true |
Switch PHP/Blade language modes in SFCs |
executablePath |
string | "" |
Custom path to blade-format binary (defaults to vendor/bin/blade-format) |
Note: Formatting options (indent size, enable/disable Pint, Tailwind, etc.) are configured in
blade-formatter.jsonorconfig/blade-formatter.php— not in VS Code settings. This keeps CLI and editor formatting consistent.
Publish and edit config/blade-formatter.php:
php artisan vendor:publish --tag=blade-formatter-config| Option | Default | Description |
|---|---|---|
paths |
['resources/views'] |
Directories to scan for Blade files |
exclude |
[] |
Paths or patterns to exclude |
indent_size |
4 |
Spaces per indentation level |
enable_pint |
true |
Format PHP in Livewire SFCs with Pint |
pint_config_path |
null |
Path to a custom pint.json |
enable_tailwind_sort |
true |
Sort Tailwind CSS classes |
prettier_path |
'npx' |
Path to Prettier binary |
enable_indentation |
true |
Auto-indent Blade templates |
When using vendor/bin/blade-format (without Artisan), create a blade-formatter.json in your project root:
{
"indent_size": 4,
"enable_pint": true,
"enable_tailwind_sort": true,
"enable_indentation": true,
"prettier_path": "npx",
"paths": ["resources/views"],
"exclude": []
}By default, the package uses npx to run Prettier, which has some startup overhead. For faster execution, point directly to your local binary:
{
"prettier_path": "node_modules/.bin/prettier"
}Livewire Single File Components combine PHP and Blade in one file:
<?php
use App\Models\User;
new class extends Component {
public string $name = '';
};
?>
<div>
<input wire:model="name" />
<p>Hello, {{ $name }}</p>
</div>Blade Formatter automatically detects SFCs and:
- Formats the PHP section with Laravel Pint
- Formats the Blade section with indentation and Tailwind sorting
- Preserves the boundary between sections
Non-SFC .blade.php files get Tailwind class sorting and auto-indentation (Pint is skipped since there's no PHP block).
Add to your CI pipeline alongside Pint:
- name: Check formatting
run: |
vendor/bin/pint --test
vendor/bin/blade-format --testThe --test flag exits with code 1 if any files need formatting, without modifying them.
MIT