Skip to content

Kirby 4.3.0


Creates one or multiple CSS link tags

css(array|string $url, array|string|null $options = null): string|null


Name Type Default Description
$url * array|string Relative or absolute URLs, an array of URLs or @auto for automatic template css loading
$options array|string|null null Pass an array of attributes for the link tag or a media attribute string

Return type



<?= css('assets/css/site.css') ?>
<?= css([
]) ?>

Autoloading template specific css files

<?= css('@auto') ?>

Template specific css files must be located in /assets/css/templates and named like the template.

Template CSS file
/site/templates/project.php /assets/css/templates/project.css
/site/templates/home.php /assets/css/templates/home.css
/site/templates/blog.php /assets/css/templates/blog.css

Media attribute

You can also specify a media attribute for the link tags:

<?= css('assets/css/print.css', 'print') ?>

Other attributes

You can also pass an array of completely custom attributes:

<?= css('assets/css/print.css', ['media' => 'print', 'data-something' => 'my-value']) ?>

For the rel attribute only alternate stylesheet is a valid value, and only if also passing a title attribute:

<?= css('assets/css/high-contrast.css', ['rel' => 'alternate stylesheet', 'title' => 'High contrast']) ?>