Reference

Guide

css()

Creates one or multiple CSS link tags

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

Parameters

Name Type Default Description
$url string|array

Relative or absolute URLs, an array of URLs or @auto for automatic template css loading

$options string|array null

Pass an array of attributes for the link tag or a media attribute string

Return type

string|null

Example

<?= css('assets/css/site.css') ?>
<?= css([
  'assets/css/site.css',
  'assets/css/form.css',
  'assets/css/grid.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']) ?>

Source code

kirby/config/helpers.php#L91