Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SigalZ's avatar

Bootstrap 5 Laravel 10 - customize colors

Hello,

I am trying to customize bootstrap 5 colors in a laravel 10 project.

I followed this tutorial:

https://www.initialapps.com/customizing-bootstrap-5-with-sass/

I don't see the new class I try to create ('my-yellow') or the new color I assign to 'primary'.

vite.conig.js:

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
    plugins: [
        laravel({
            input: [
                'resources/admin/admin.scss', 
                'resources/admin/admin.js',
                'resources/assets/js/app.js',
                'resources/assets/sass/app.scss'
            ],
            refresh: true,
        }),
    ],
});

In app.scss:

// 1. Include functions first (so you can manipulate colors, SVGs, calc, etc)
@import "../../../node_modules/bootstrap/scss/functions";

// 2. Include any default variable overrides here
//@import "variables";
$primary: #D4CBE5;

// 3. Include remainder of required Bootstrap stylesheets (including any separate color mode stylesheets)
@import "../../../node_modules/bootstrap/scss/variables";
@import "../../../node_modules/bootstrap/scss/variables-dark";



// 4. Include any default map overrides here
// Create your own map
$custom-colors: (  
  "my-yellow": $indigo-900
);

// Merge the maps
$theme-colors: map-merge($theme-colors, $custom-colors);

// Bootstrap
//@import "node_modules/bootstrap-sass3/assets/stylesheets/bootstrap";
@import "../../../node_modules/bootstrap/dist/css/bootstrap";

// bring in main
@import "main";

I have this in my layout:

@vite(['resources/assets/sass/app.scss'])

In my blade:

<a class="btn btn-lg btn-my-yellow" href="#" role="button">Get Your Beans</a>

The link displays as simple text without the background color.

If I change it to:

<a class="btn btn-lg btn-primary" href="#" role="button">Get Your Beans</a>

I see bootstrap's primary color and not the one I assigned.

Why is that?

0 likes
9 replies
JussiMannisto's avatar

Have you rebuilt the assets, or are you using hot reloading?

SigalZ's avatar

I'm running npm run dev and I see the new app.scss in the page source

JussiMannisto's avatar

@SigalZ App.scss should not be in the page source. SCSS doesn't mean anything to a browser; it needs to be compiled into CSS files that are then added to the source. I don't think this part should be there:

@vite(['resources/assets/sass/app.scss'])
SigalZ's avatar

@JussiMannisto thank you

From Laravel documentation:

<!doctype html>
<head>
    {{-- ... --}}
 
    @vite(['resources/css/app.css', 'resources/js/app.js'])
</head>

I change my code to:

@vite('resources/css/app.css')

I changed the vite.config.js as well:

export default defineConfig({
    plugins: [
        laravel({
            input: [
                'resources/admin/admin.scss', 
                'resources/admin/admin.js',
                'resources/assets/js/app.js',
                'resources/assets/css/app.css'
            ],
            refresh: true,
        }),
    ],

But now I don't see any styles at all. There is no resources/css/app.css file.

I don't understand anything about mixings so I guess I am missing a step.

What creates the css/app.css file?

And how come I do see changes I make in main.scss?

JussiMannisto's avatar

@SigalZ You still need to include the SCSS file so that it gets compiled by Vite. Just don't add it in the page source.

I don't know what main.scss is. You haven't mentioned it before.

What technology are you using for the front end: Vue, React, Blade, something else?

JussiMannisto's avatar

You're including multiple sass files. Could that be the issue? Does admin.scss use bootstrap?

SigalZ's avatar

For testing, I went into: node_modules/bootstrap/scss/_variables.scss and changed:

$primary:       $yellow !default;

Page refreshed, and primary is still blue.

Looking at bootstrap documentation, I change my app.scss to:

// Required
@import "../../../node_modules/bootstrap/scss/functions";

// Default variable overrides
$primary: #D4CBE5;

// Required
@import "../../../node_modules/bootstrap/scss/variables";
@import "../../../node_modules/bootstrap/scss/variables-dark";
@import "../../../node_modules/bootstrap/scss/maps";
@import "../../../node_modules/bootstrap/scss/mixins";
@import "../../../node_modules/bootstrap/scss/root";

// 4. Include any default map overrides here
// Create your own map
$custom-colors: (  
  "my-yellow": $indigo-900
);

// Merge the maps
$theme-colors: map-merge($theme-colors, $custom-colors);

// Bootstrap
//@import "node_modules/bootstrap-sass3/assets/stylesheets/bootstrap";
@import "../../../node_modules/bootstrap/dist/css/bootstrap";
``

Nada! Does not work.

I don't understand.
SigalZ's avatar

OMG!!! I found the problem!

In app.scss change this line:

@import "../../../node_modules/bootstrap/dist/css/bootstrap";

to:

@import "../../../node_modules/bootstrap/scss/bootstrap";

Please or to participate in this conversation.