Yii2 supports Bootstrap as a core feature. Bootstrap framework CSS and JavaScript files are injected by default in all pages and we could even use this feature to only apply CSS classes or call our own JavaScript function provided by Bootstrap.

However, Yii2 embeds Bootstrap as a widget, and we can access this framework’s capabilities like any other widget.

The most used are:

Class name Description
yiibootstrapAlert This class renders an alert Bootstrap component
yiibootstrapButton This class renders a Bootstrap button
yiibootstrapDropdown This class renders a Bootstrap drop-down menu component
yiibootstrapNav This class renders a nav HTML component
yiibootstrapNavBar This class renders a navbar HTML component

For example, yiibootstrapNav and yiibootstrapNavBar are used in the default main template.

This is an extract from the main layout view (in basic/views/layouts/main.php):

                'brandLabel' => 'My Company',
                'brandUrl' => Yii::$app->homeUrl,
                'options' => [
                    'class' => 'navbar-inverse navbar-fixed-top',
            echo Nav::widget([
                'options' => ['class' => 'navbar-nav navbar-right'],
                'items' => [
                    ['label' => 'Home', 'url' => ['/site/index']],
                    ['label' => 'About', 'url' => ['/site/about']],
                    ['label' => 'Contact', 'url' => ['/site/contact']],
                    Yii::$app->user->isGuest ?
                        ['label' => 'Login', 'url' => ['/site/login']] :
                        ['label' => 'Logout (' . Yii::$app->user->identity->username . ')',
                            'url' => ['/site/logout'],
                            'linkOptions' => ['data-method' => 'post']],