ホーム>Laravel>How to comment out in Laravel Blade ({{-- --}} vs <!-- -->)
Laravel

How to comment out in Laravel Blade ({{-- --}} vs <!-- -->)

Thank you for your continued support.
This article contains advertisements, including affiliate links, that help fund our operations.
As an Amazon Associate, Laratech earns from qualifying purchases.

How to comment out in Laravel Blade: the difference between {{-- --}} and HTML <!-- --> comments, commenting out @if and @include, and why Blade comments can't be nested, checked on Laravel 13.

What is a comment out?

It is something that is not displayed to users but remains as a note in the file.

For example,

<html>
  <!-- This text will not be displayed -->
</html>

It can be used like this.

How to comment out in Laravel Blade

In Laravel blade, you can comment out just like regular HTML.

test.blade.php

<html>
  <!-- This text will not be displayed -->
</html>

You can comment out exactly like an HTML file, so this should be fine most of the time.

(Added on 2026-11-08) HTML comments are not shown on the screen, but they are still sent to the browser.

Anyone can read them by viewing the page source, so use {{-- --}} below for notes you don't want to expose.

How to comment out in parts dealing with data

When you comment out in parts dealing with data,

<html>
  <!-- {{ $post->title }} -->
</html>

$post->title will be retrieved but not displayed.

The next method is a way to not retrieve data (do not execute functions) in the first place.

{{-- $post->title --}}

By writing like this, you can comment out in a way that the functions usable in blade are not executed in the first place.

In other examples,

{{--
 @if($user)

 @endif
 --}}

You can prevent the execution of functions like @if in blade.

The benefit of this is that by not executing functions or retrieving data in the first place, you can avoid strange bugs or unnecessary processing.

Please take advantage of this.

What Laravel 13 actually outputs

In November 2026, this was checked on Docker's php:8.4-cli (PHP 8.4.27) with Laravel 13.40.0 by fetching the page with curl.

<!-- {{ $post->title }} -->
{{-- {{ $post->title }} --}}

With $post->title set to "Secret title", the returned HTML was:

<!-- Secret title -->

The {{ }} inside <!-- --> is executed and the value ends up in the HTML.

The {{-- --}} line disappears completely; it is removed when the view is compiled and does not even remain in the compiled PHP under storage/framework/views/.

Because Blade still runs inside <!-- -->, errors still happen there too.

<!-- {{ $undefinedPost->title }} --> returned HTTP 500 (Undefined variable $undefinedPost), and <!-- @include('parts.sidebar') --> for a view that doesn't exist returned HTTP 500 (View [parts.sidebar] not found.).

Wrapped in {{-- --}} instead, both pages returned 200.

{{-- --}} cannot be nested.

{{-- outer {{-- inner --}} rest --}} ends at the first --}}, and rest --}} was printed on the page.

The official documentation also explains that, unlike HTML comments, Blade comments are not included in the HTML returned by your application.

Blade Templates - Comments (Laravel documentation)

Conclusion

That's all.

I hope it helps someone.

That's it!

Please Provide Feedback
We would appreciate your feedback on this article. Feel free to leave a comment on any relevant YouTube video or reach out through the contact form. Thank you!