how to include my css file ?

hi, I have css file created and I am confuse where to put this in yii and how to call it in yii so that my css file will be render.

Thank you in advance.


There is an array which you need to add the file reference to:

public $css = [



Create new YourAssetClass extend yii\web\AssetBundle, example:

namespace app\assets;

class YourAsset extends yii\web\AssetBundle


    // your css, js..., see app\assets\AppAsset in basic template for demo


then in view:


Hope it help you! :)

Thank you for the quick reply… ‘MyAssetClass’ should be put in this directory-> assets/MyAssetClass.php

Thank you.

Thank you,so how will you going to call that ? or how can I access that ? the way what is the difference between your answer and to Tuan Ho ?

In basic template, AppAsset is registed in main layout:


it mean if you add your css/js here, your css/js will render in all page (with main layout)

With my solution, you will register your Asset when you need, example in dasboard page you need draw chart (only dasboard page), so you create NewAsset and register it in dasboard view => js/css for draw chart will render in dasboard page only

My answer assumed, you are using basic install (which I guess you are if you’re new to yii2), in which case AppAsset is already set up and called in the main layout. His answer assumes you need to create your AppAsset class.