Bootstrap 5 Colors Tutorial 🎯

beginner
17 min

Bootstrap 5 Colors Tutorial 🎯

Welcome to our comprehensive guide on Bootstrap 5 colors! In this lesson, we'll dive into the world of colors in Bootstrap 5, learning how to use them effectively in your projects.

Understanding Bootstrap 5 Colors 📝

Bootstrap 5 provides a vast array of predefined colors to help you create visually appealing and consistent designs. These colors are defined within the framework, making it easy for you to apply them to your HTML elements.

Basic Color Syntax 💡

In Bootstrap 5, you can apply colors to your HTML elements using the .text-* and .bg-* classes. Here's a simple example:

html
<div class="bg-primary">This is a primary background color.</div> <div class="text-secondary">This is a secondary text color.</div>

In the example above, we're using the .bg-primary and .text-secondary classes to set the background and text colors, respectively.

Exploring Predefined Colors 🎨

Bootstrap 5 offers a variety of predefined colors for you to use in your projects. Here's a quick look at some of them:

Primary Colors ✅

  • Primary: A bold, vibrant blue used for primary actions and branding.
  • Secondary: A neutral grey used for secondary text and backgrounds.
  • Success: A lime green used for positive feedback and success states.
  • Danger: A bright red used for error messages and warnings.
  • Warning: A yellow used for caution and alerts.
  • Info: A light blue used for informational messages.

Additional Colors ✅

  • Light: A light grey used for subtle backgrounds and text.
  • Dark: A dark grey used for darker backgrounds and text.

Customizing Colors 💡

Bootstrap 5 also allows you to customize colors using variables. This can be particularly useful when you want to create a unique color scheme for your project.

css
/* Define custom primary color */ $primary: #333; /* Use custom primary color in your HTML */ <div class="bg-primary">This is a custom primary background color.</div>

In the example above, we're defining a custom primary color using the Sass $primary variable and then applying it to our HTML element using the bg-primary class.

Practical Application 🎯

Let's put our knowledge into practice by creating a simple page with different colors.

html
<!doctype html> <html lang="en"> <head> <title>Bootstrap 5 Colors</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg5Qhq9gYmV48/VFnIRjh1z9g4N3xk6iwJLpUCgY5B3q607C6wzDnYs7VA" crossorigin="anonymous"> </head> <body> <div class="container"> <h1 class="text-primary">Primary Text</h1> <h1 class="text-secondary">Secondary Text</h1> <h1 class="text-success">Success Text</h1> <h1 class="text-danger">Danger Text</h1> <h1 class="text-warning">Warning Text</h1> <h1 class="text-info">Info Text</h1> <h1 class="text-light">Light Text</h1> <h1 class="text-dark">Dark Text</h1> </div> </body> </html>

In this example, we're creating a simple page with headings of different colors.

Quiz Time 🎯

Quick Quiz
Question 1 of 1

What class would you use to set the text color to light grey in Bootstrap 5?

That's all for today! We've covered the basics of Bootstrap 5 colors, explored predefined colors, and learned how to customize colors using variables. Stay tuned for more lessons on Bootstrap 5! 🎯