Prettier Plugin for Blade

Stop waiting
for your formatter.

A real recursive-descent parser — compiled from Dart to JavaScript — formats your Blade templates in milliseconds. No regex. No child processes. No compromises.

$ npm i -D prettier-plugin-laravel-blade prettier Copied
0.66ms
Avg format time
~160 KB
Package size
228
Fixtures tested
--
Idempotent
Performance
Measured, not claimed
Average format time across 228 fixtures. 100 timed runs after warmup. Run it yourself →
This plugin stillat shufo chisel

Why so fast?

  • 0 IPC Runs in-process, no child processes
  • dart2js Dart parser compiled to optimized JS
  • In-process Lexer → Parser → Formatter, all in-memory
  • No regex Real recursive-descent, no backtracking
  • ~160 KB vs 777 KB vs 12+ MB
  • 0 deps No blade-formatter or php-parser
Capabilities
Everything Blade throws at you
First-class support for the full Laravel ecosystem — directives, components, and frontend frameworks.
@

120+ Directives

Every built-in: @if, @foreach, @forelse, @auth, @guest, @switch, @push, @section, @extends, @yield, @component, and more.

<x>

Blade Components

Full <x-component> support with named slots, attributes, and deeply nested content. Properly indents <x-slot:name> blocks.

::

Alpine.js & Livewire

x-data, @click, :bind, x-show, x-transition, wire:model, wire:click, wire:poll — all modifiers handled correctly.

f(f(x))

Stable Output

Format once or a hundred times — identical output. No trailing spaces, no oscillating blank lines, no second-save diffs.

//

Smart Attribute Wrapping

Respects printWidth. Choose auto, always, or never. Configurable closing bracket position and self-closing style.

*

12 Custom Options

Quote style, directive spacing, slot formatting, slot name style, slot spacing, wrap attributes, attribute sorting, closing bracket, self-closing, echo spacing, HTML block spacing, trailing newline.

Output
Correct nesting, every time
Deeply interleaved Blade and HTML get proper hierarchical indentation — not collapsed onto one line.
Input — editable, try it
Formatted

          
Input — editable, try it
Formatted

          
Comparison
Side by side with every alternative
Tested against stillat's prettier-plugin-blade (v2.1.21), shufo's @shufo/prettier-plugin-blade (v1.16.1), and Chisel v3 (prettier-plugin-blade v3).
This plugin stillat shufo chisel
Package size ~160 KB 777 KB 12+ MB ~2.6 MB
Avg format time 0.66 ms 13.23 ms 16.55 ms -- ms
Parser Recursive-descent AST TypeScript AST (Prettier IR) Heuristic-based (no AST) TypeScript AST (Prettier IR)
Idempotent 219/228 207/228 224/228 224/228
Dependencies None None blade-formatter, php-parser 3 (html-tags, parse-srcset, html-element-attributes)
Trailing whitespace ✓ None ✗ Present ✓ None ✓ None
Quote handling Dedicated option (preserve/single/double) Uses Prettier's singleQuote Uses Prettier's singleQuote Uses Prettier's singleQuote
Nested directives ✓ Correct hierarchy ✓ Correct ✗ Collapses levels ✓ Correct
<x-slot> formatting ✓ Fully expanded Keeps inline ✗ Misaligned ✓ Fully expanded
PHP formatting ✗ Not supported Via Laravel Pint Via blade-formatter ✓ Built-in (safe/aggressive)
Alpine.js value formatting ✓ Via Prettier x-data only (via js_beautify) ✓ Via Prettier
Component prefixes x- only x- only x- only ✓ Configurable (x, flux, livewire…)
Architecture Compiled Dart (dart2js) TypeScript → Prettier IR blade-formatter wrapper TypeScript (ground-up rewrite)
Links GitHub · npm GitHub · npm GitHub · npm GitHub · npm
Architecture
How it works
A full Dart parser compiled to optimized JavaScript runs inside Node.js — zero IPC, zero filesystem overhead.
Input
.blade.php
Source template
Step 1
Prettier
Calls preprocess
Step 2
Dart AST
Recursive-descent parser
Step 3
Format
Visitor traversal
Output
Done
~1 ms avg
Configuration
Fine-grained control
12 Blade-specific options alongside Prettier's standard tabWidth, useTabs, and printWidth.
Option Default Choices Description
bladeQuoteStyle "preserve" single, double, preserve ' vs " in attribute values
bladeDirectiveSpacing "between_blocks" between_blocks, none, preserve Blank lines between @if, @foreach, etc.
bladeSlotFormatting "compact" compact, block Extra newlines inside <x-slot> blocks
bladeSlotNameStyle "colon" colon, attribute, preserve <x-slot:name> vs <x-slot name="...">
bladeSlotSpacing "after" none, after, before, around Blank lines before/after <x-slot> tags
bladeWrapAttributes "auto" auto, always, never Multi-line attributes when line is too long
bladeAttributeSort "none" none, alphabetical, by_type Reorder attributes (HTML → Alpine → Livewire)
bladeClosingBracketStyle "same_line" same_line, new_line Where > sits when attributes wrap
bladeSelfClosingStyle "preserve" preserve, always, never <x-icon /> vs <x-icon></x-icon> for empty tags
bladeHtmlBlockSpacing "between_blocks" between_blocks, none, preserve Blank lines between block-level HTML siblings
bladeEchoSpacing "spaced" spaced, compact, preserve Spacing inside {{ }} and {!! !!} braces
bladeTrailingNewline true true, false Add trailing newline at end of output
.prettierrc
{
  "plugins": ["prettier-plugin-laravel-blade"],
  "overrides": [{
    "files": "*.blade.php",
    "options": {
      "tabWidth": 4,
      "printWidth": 120,
      "bladeSlotFormatting": "compact",
      "bladeSlotNameStyle": "colon",
      "bladeSlotSpacing": "after",
      "bladeWrapAttributes": "auto",
      "bladeAttributeSort": "by_type",
      "bladeSelfClosingStyle": "preserve",
      "bladeHtmlBlockSpacing": "between_blocks",
      "bladeEchoSpacing": "spaced",
      "bladeTrailingNewline": true
    }
  }]
}
.blade.json
{
  "indent_size": 4,
  "indent_style": "spaces",
  "max_line_length": 120,
  "slot_formatting": "compact",
  "slot_name_style": "colon",
  "slot_spacing": "after",
  "wrap_attributes": "auto",
  "attribute_sort": "by_type",
  "self_closing_style": "preserve",
  "html_block_spacing": "between_blocks",
  "echo_spacing": "spaced",
  "trailing_newline": true
}

Try it now

Works with Prettier 3.x. Just add the plugin to your .prettierrc.

Open Live Formatter View Source
# Install
npm install --save-dev prettier-plugin-laravel-blade prettier

# Add to .prettierrc
echo '{ "plugins": ["prettier-plugin-laravel-blade"] }' > .prettierrc

# Format
npx prettier --write "**/*.blade.php"

# Check (CI)
npx prettier --check "**/*.blade.php"