Bootstrap Icons: Practical Guide

By Maulik Paghdal

21 Dec, 2024

Bootstrap Icons: Practical Guide

Bootstrap Icons are a versatile and customizable library of vector icons built for the Bootstrap framework but usable anywhere. With over 1,800 icons covering various design needs, they are perfect for enhancing user interfaces. This practical guide will walk you through using Bootstrap Icons, from installation to advanced customization.

What Are Bootstrap Icons?

Bootstrap Icons are SVG-based icons designed to work seamlessly with Bootstrap components. However, you can use them in any project, regardless of whether you are using Bootstrap.

Key Features:

  • Free and open-source.
  • Lightweight and scalable.
  • Over 1,800 icons with continuous updates.

Step 1: Installing Bootstrap Icons

Method 1: Using a CDN

The quickest way to use Bootstrap Icons is by including the CDN link in your HTML file.

<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">

When to Use: Ideal for quick prototyping or lightweight projects.

Method 2: Installing via npm

For larger projects, use npm to install Bootstrap Icons.

npm install bootstrap-icons

Then, include the CSS in your project:

@import "node_modules/bootstrap-icons/font/bootstrap-icons.css";

When to Use: Suitable for modern workflows with build tools.

Step 2: Using Icons in HTML

Once installed, you can easily include icons using the <i> tag with the bi class.

Example:

<i class="bi bi-alarm"></i>

Output:

A scalable alarm icon will appear on the page.

Step 3: Customizing Bootstrap Icons

1. Changing Icon Size

Bootstrap Icons scale with font-size. Use CSS or utility classes to resize icons.

<i class="bi bi-alarm" style="font-size: 2rem;"></i>

Example with Utility Class:

<i class="bi bi-alarm fs-3"></i>

2. Adding Colors

Change the icon color using the color property in CSS or Bootstrap utility classes.

<i class="bi bi-alarm text-primary"></i>

Result: The icon will be styled with the Bootstrap primary color.

3. Rotating and Flipping Icons

Use utility classes to rotate or flip icons:

  • Rotate:
<i class="bi bi-arrow-clockwise rotate-90"></i>
  • Flip:
<i class="bi bi-arrow-right flip-horizontal"></i>

Bootstrap Icons integrate seamlessly with buttons and links.

Example:

<button class="btn btn-primary">
  <i class="bi bi-check-circle"></i> Submit
</button>

Result: A button with a check-circle icon.

Advanced Tips for Bootstrap Icons

1. Accessibility

Always add aria-label or title attributes for better accessibility.

<i class="bi bi-info-circle" aria-label="Information"></i>

2. Custom SVG Icons

For unique designs, modify SVG code directly. Download SVG files from the Bootstrap Icons Library.


Frequently Used Icons

Here are some commonly used Bootstrap Icons:

  1. Search:
<i class="bi bi-search"></i>

Preview:Bootstrap Search Icon

  1. User:
<i class="bi bi-person"></i>

Preview:Bootstrap Person Icon

  1. Trash:
<i class="bi bi-trash"></i>

Preview:Bootstrap Trash Icon

  1. Cart:
<i class="bi bi-cart"></i>

Preview:Bootstrap Cart Icon


Why Choose Bootstrap Icons?

  • Lightweight: Minimal performance impact.
  • Scalable: Perfect for responsive designs.
  • Customizable: Tailor icons to match your brand.

Conclusion

Bootstrap Icons are a fantastic tool for modern web development. With easy installation, a vast collection, and customization options, they streamline the process of adding visually appealing icons to your project.

Start using Bootstrap Icons today and elevate your design!

Topics Covered