Bootstrap / Bootstrap Themes and Customization

Modifying Bootstrap Variables

This tutorial introduces you to Bootstrap variables and how they can be used to customize Bootstrap. You'll learn how to modify these variables to achieve a wide range of customiz…

Tutorial 3 of 5 5 resources in this section

Section overview

5 resources

Explores how to customize Bootstrap and create custom themes.

1. Introduction

In this tutorial, we will explore the world of Bootstrap variables and learn how to modify them to customize your Bootstrap themes. By the end of this tutorial, you will be able to customize Bootstrap's default variables to suit your design needs.

You will learn:
- What Bootstrap variables are.
- How to modify Bootstrap variables.
- How to use modified variables in your project.

Prerequisites:
- Basic knowledge of HTML and CSS.
- Understanding of SASS/SCSS.
- Basic understanding of Bootstrap framework.

2. Step-by-Step Guide

Bootstrap Variables

Bootstrap uses SASS variables to customize the design of its components. These variables are defined in the _variables.scss file in Bootstrap's source code. By modifying these variables, you can change the default styling of Bootstrap.

How to Modify Bootstrap Variables

To modify Bootstrap variables, you first need to have a SASS processing setup in your project. This is because Bootstrap's source code is written in SASS.

Once your SASS setup is ready, follow these steps:

  1. Import Bootstrap's source code into your project.
  2. Before the Bootstrap import, declare your custom values for the variables you want to change.
  3. Compile your SASS code into CSS.

Here is a basic example:

$primary: #5a7791;

@import 'bootstrap';

In the above example, the $primary variable is overridden with a custom color before importing the Bootstrap source code.

3. Code Examples

Let's take a look at some examples.

Example 1: Changing Primary Color

// Changing the primary color
$primary: #5a7791;

// Importing Bootstrap
@import 'bootstrap';

Here, we are changing the primary color from Bootstrap's default blue to a custom color.

Example 2: Changing Font Size Base

// Changing the base font size
$font-size-base: 1rem;

// Importing Bootstrap
@import 'bootstrap';

In this example, we are changing the base font size from Bootstrap's default to 1rem.

4. Summary

In this tutorial, we covered how to modify Bootstrap variables to customize the Bootstrap theme. We learned the importance of SASS in the process and saw several examples of how to change different types of variables.

To dive deeper into Bootstrap customization, you can explore the _variables.scss file in Bootstrap's source code to see all the available variables.

5. Practice Exercises

Exercise 1:
Change the $grid-gutter-width variable to 40px.

Solution:

$grid-gutter-width: 40px;
@import 'bootstrap';

Exercise 2:
Change the $border-radius variable to 10px.

Solution:

$border-radius: 10px;
@import 'bootstrap';

Exercise 3:
Combine what you have learned and change the $primary color, $font-size-base, and $grid-gutter-width all at once.

Solution:

$primary: #5a7791;
$font-size-base: 1rem;
$grid-gutter-width: 40px;

@import 'bootstrap';

For further practice, explore other variables in the _variables.scss file and try modifying them.

Need Help Implementing This?

We build custom systems, plugins, and scalable infrastructure.

Discuss Your Project

Related topics

Keep learning with adjacent tracks.

View category

HTML

Learn the fundamental building blocks of the web using HTML.

Explore

CSS

Master CSS to style and format web pages effectively.

Explore

JavaScript

Learn JavaScript to add interactivity and dynamic behavior to web pages.

Explore

Python

Explore Python for web development, data analysis, and automation.

Explore

SQL

Learn SQL to manage and query relational databases.

Explore

PHP

Master PHP to build dynamic and secure web applications.

Explore

Popular tools

Helpful utilities for quick tasks.

Browse tools

Fake User Profile Generator

Generate fake user profiles with names, emails, and more.

Use tool

Countdown Timer Generator

Create customizable countdown timers for websites.

Use tool

CSV to JSON Converter

Convert CSV files to JSON format and vice versa.

Use tool

Unit Converter

Convert between different measurement units.

Use tool

Age Calculator

Calculate age from date of birth.

Use tool

Latest articles

Fresh insights from the CodiWiki team.

Visit blog

AI in Drug Discovery: Accelerating Medical Breakthroughs

In the rapidly evolving landscape of healthcare and pharmaceuticals, Artificial Intelligence (AI) in drug dis…

Read article

AI in Retail: Personalized Shopping and Inventory Management

In the rapidly evolving retail landscape, the integration of Artificial Intelligence (AI) is revolutionizing …

Read article

AI in Public Safety: Predictive Policing and Crime Prevention

In the realm of public safety, the integration of Artificial Intelligence (AI) stands as a beacon of innovati…

Read article

AI in Mental Health: Assisting with Therapy and Diagnostics

In the realm of mental health, the integration of Artificial Intelligence (AI) stands as a beacon of hope and…

Read article

AI in Legal Compliance: Ensuring Regulatory Adherence

In an era where technology continually reshapes the boundaries of industries, Artificial Intelligence (AI) in…

Read article

Need help implementing this?

Get senior engineering support to ship it cleanly and on time.

Get Implementation Help