Craft 3 Documentation

{% css %}

The {% css %} tag can be used to register a <style> tag in the page’s <head>.

{% css %}
    .content { 
        color: {{ entry.textColor }};
    }
{% endcss %}

The tag calls yii\web\View::registerCss() under the hood, which can also be accessed via the global view variable.

{% set styles = ".content { color: #{entry.textColor}; }" %}
{% do view.registerCss(styles) %}

Parameters #

The {% css %} tag supports the following parameters:

with #

Any HTML attributes that should be included on the <style> tag.

{% css with {type: 'text/css'} %}

Attributes will be rendered by yii\helpers\Html::renderTagAttributes().