DEV Community

Anusree Anilkumar
Anusree Anilkumar

Posted on Originally published at anusree6154s.github.io on

Using Bootstrap Icons

1. Install Bootstrap Icons (Recommended - I use this)

If you’re using a package manager like npm or yarn, install Bootstrap Icons:

npm install bootstrap-icons

Enter fullscreen mode Exit fullscreen mode

or

yarn add bootstrap-icons

Enter fullscreen mode Exit fullscreen mode

Then, import the CSS in your index.js or App.js :

import 'bootstrap-icons/font/bootstrap-icons.css';

Enter fullscreen mode Exit fullscreen mode

Now, you can use icons like this in your components:

<i className="bi bi-heart"></i>

Enter fullscreen mode Exit fullscreen mode

2. Use Bootstrap Icons via CDN (Alternative)

If you don’t want to install the package, add this CDN link in your index.html (inside <head>):

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

Enter fullscreen mode Exit fullscreen mode

Then, you can use icons directly in your components:

<i className="bi bi-heart"></i>

Enter fullscreen mode Exit fullscreen mode

3. Using Icons as React Components (For Better Performance)

Instead of <i> tags, you can import SVG icons directly:

import { ReactComponent as HeartIcon } from 'bootstrap-icons/icons/heart.svg';

const MyComponent = () => {
  return <HeartIcon width="24" height="24" fill="red" />;
};

Enter fullscreen mode Exit fullscreen mode

Top comments (0)