Skip to main content

Introduction

Blade is the simple yet powerful templating engine included with Laravel. Unlike some PHP templating engines, Blade does not restrict you from using plain PHP code in your templates. All Blade templates are compiled into plain PHP and cached, so Blade adds virtually zero overhead to your application. Blade template files use the .blade.php extension and are stored in the resources/views directory.

Displaying data

Display data passed to a Blade view by wrapping the variable in double curly braces:
Blade’s {{ }} syntax automatically passes output through PHP’s htmlspecialchars function to prevent XSS attacks.
You can also display the result of any PHP expression:

Unescaped output

Use the {!! !!} syntax when you need to render raw HTML without escaping:
Always use {{ }} for user-supplied data. Using {!! !!} with untrusted input creates XSS vulnerabilities.

Coexisting with JavaScript frameworks

When your JavaScript framework also uses curly brace syntax, prefix the expression with @ to tell Blade to leave it alone:
Blade removes the @ symbol, and {{ name }} is sent as-is to the browser for your JavaScript framework to render.
If you want to compare Blade with Livewire, Inertia, and SPA-style setups, see Frontend.

Blade directives

Conditionals

Use @unless to express “if not”:
Check whether a variable is defined or non-empty with @isset and @empty:

Authentication directives

Switch statements

Loops

Blade provides convenient directives for every common loop type:
Use @break and @continue to control loop execution:
You can also pass a condition directly to the directive:

The loop variable

Inside @foreach loops, the $loop variable gives you useful information about the current iteration:

Comments

Blade comments are never included in the rendered HTML:

Layouts

Component-based layouts

Using Blade components is the recommended approach for building layouts in modern Laravel applications. First, create a layout component:
Then use the layout in a view:

Template inheritance

The classic approach uses @extends, @section, and @yield: Defining the parent layout:
Extending the layout in a child view:
@parent lets you append to the parent’s @section content instead of replacing it.

Including sub-views

Use @include to embed another Blade view. All variables available in the parent view are automatically available in the included view:
Pass additional variables when including a view:

CSRF protection in forms

HTML forms in the web routes file that send POST, PUT, PATCH, or DELETE requests must include the @csrf directive:
To send PUT, PATCH, or DELETE requests from an HTML form, use the @method directive:
See CSRF protection for origin verification, token fallback behavior, and AJAX header strategies (X-CSRF-TOKEN / X-XSRF-TOKEN).

Summary

{{ $variable }} for escaped output, {!! $variable !!} for raw (unescaped) output.
@if, @elseif, @else, @endif, @unless, @isset, @empty, @auth, @guest.
@for, @foreach, @forelse, @while with $loop variable for iteration metadata.
Component-based layouts (<x-layout> with {{ $slot }}) or template inheritance (@extends, @section, @yield).
@include to embed reusable view partials.
Last modified on May 27, 2026