Posts Learn Components Snippets Categories Tags Tools About

How to Display HTML in Laravel Blade

Learn how to display HTML in Laravel Blade that's returned from a source that's a string value

Created on Oct 01, 2021


Sometimes you might have a string of HTML tags/components that's returned from the database or 3rd party source and you want to render it in Laravel Blade. If using the normal blade "{{ $content }}" curly braces to output it, it will be rendered as a string and not HTML. This behavior happens because Laravel by default escapes the value when using the syntax.
{{ $content }}
To render the raw HTML you will have to unescape it and to do that you can make use of the following syntax.
{!! $renderHTMLContent !!}
By default using the syntax above automatically unescapes any value using the PHP "htmlspecialchars" function but make sure to validate the data if it's entered by the user. Behind the scene, the compiled template looks like below.
{{ $content }} is converted to <?php echo e($content); ?>
While for the unescaped version, it will be as follows.
{!! $renderHTMLContent !!} is converted to <?php echo $renderHTMLContent; ?>

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

Load comments for How to Display HTML in Laravel Blade