41

When I use any JS-module with NPM, I include it into my .js file with require(""). How can I do the same with Bootstrap icons and include them into .html? Their official docs and npm wasn't clear enough for me.

I don't use Bootstrap in my project, only few icons, is it enough to have only this package?

npm install bootstrap-icons

Are Bootstrap icons really free? Should you mention them in the project?

5 Answers 5

61

Additional 28 June 2021

after import using NPM you can import CSS file to react with :

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

and use like this :

<i className="icon bi-envelope"></i>

if you only want to use the bootstrap-icons.svg from node_modules, you can copy it manually or with webpack. If you copy in root folder, you can use like this :

<svg class="bi" width="32" height="32" fill="currentColor">
     <use xlink:href="bootstrap-icons.svg#bootstrap"/>
</svg>

If you copy in icons folder :

<svg class="bi" width="32" height="32" fill="currentColor">
     <use xlink:href="icons/bootstrap-icons.svg#bootstrap"/>
</svg>

or copy the icons/*.svg for use only icon what you need, and you can use it like this :

<img src="bootstrap.svg" alt="" width="32" height="32" title="Bootstrap">

Are bootstrap icons really free?

yes, bootstrap icons is free https://github.com/twbs/icons/blob/main/LICENSE.md

Should you mention them in the project?

you need to including copyright notice in your project. its enough, but if you want to mention it, create about page and included all software you use there that would be super nice.

note : Oct 2020

Sign up to request clarification or add additional context in comments.

3 Comments

Was looking everywhere through their docs and online trying to figure out why the <i class....></i> wasn't working with my VueJS project. The import of the the .css was what was missing. Their doc doesn't cover that at all. Thanks.
Import "bootstrap-icons/font/bootstrap-icons.css". Not sure why this is missing in their docs, was looking for the file path to import and couldn't seem to find it mentioned anywhere. Thanks!!
Rio A.P, how did you find this solution?
27
npm install bootstrap-icons

Then open your app/javascript/stylesheets/application.scss and add the path to your bootstrap-icons.css file, usually, it should look like something like this

@import '~bootstrap-icons/font/bootstrap-icons';

3 Comments

I imported to the main SCSS like this: @import "../../../node_modules/bootstrap-icons/font/bootstrap-icons"; Then use <i class="bi bi-chevron-bar-right"></i> in HTML. I see only white square. Should i copy something else from the bootstrap-icons npm folder)?
This works for me only if I add explicitly add the .css extension in the include, otherwise it throws an error. So in your main scss file (that also holds the scss imports) do: @import '~bootstrap-icons/font/bootstrap-icons.css';
I was able to get this to work with a combination of the two comments above. @import '../node_modules/bootstrap-icons/font/bootstrap-icons.css. I tried importing with the tilde format, using the full relative path to the scss file, including the scss file. But it only worked to use a relative path from the scss file to the css file in the bootstrap-icons project
1

I installed the icons using yarn in my Next.js application

I followed the following steps

  1. yarn add bootstrap-icons
  2. Add import "bootstrap-icons/font/bootstrap-icons.css"; to the index.tsx file (I'm using typescript)
  3. Test by adding an icon in the index.tsx like <i className="bi bi-list"></i>

It worked for me

Comments

0

I installed the icons via npm

npm i bootstrap-icons

and added them to the style file

@import "~bootstrap-icons/font/bootstrap-icons";

, but instead of the icons I have the same squares (the same way I added Bootstrap styles from NPM and everything is fine with them). I tried all the add options from the documentation, nothing works (except for a full-fledged SVG). this is what the icons look like

1 Comment

This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review
-3

Add the following CDN to your index.html

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

1 Comment

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.