← All articles
Use critical CSS in Statamic 3
In this post we show you how to use critical CSS in your Statamic 3 website.

This is part two of our series. In part one we explained what critical CSS is and how to generate critical CSS for your website with node. In this part we show you
How to inline critical CSS in Statamic 3?
First download and install the add-on Inline Assets from developer octoper.
Create a new tag file, App/Tags/Templatename.php:
<?php
namespace App\Tags;
use Statamic\Tags\Tags;
class Templatename extends Tags
{
public function index()
{
$url = $this->params->get('name');
return basename($url);
}
}
Insert this code in the <head> section of your main.antlers.html:
<style>
{{ inlineassets:css src="pathToCriticalCss/{ templatename name='{currenttemplate}' }_critical.min.css" ignore-missing="true" }}
</style>
<link rel="stylesheet" href="pathTo/normal.css" media="print" onload="this.media='all'">
That’s it. Now you’ve got fast-loading, non-render-blocking critical CSS.