Add bootstrap icons in React
Today, we will show you how to add bootstrap icons in React application. There are multiple icons libraries to render icons in React application like Font Awesome, Ant Design Icons, Flat Color Icons, etc.
Demo Application
Add bootstrap icons in React
1. Project structure
Refer to the following project structure for demo application.
- react-bootstrap-icons
- node_modules
- public
- index.html
- src
- App.js
- index.css
- index.js
- package-lock.json
- package.json
- README.md
2. Package dependencies
In this example, we have to install the bootstrap-icons npm package. Run the following command to install the bootstrap-icons
.
1 | npm i bootstrap-icons |
You will find the version of following packages in React application.
3. Add bootstrap icons in component
First, we have to add the following CSS in React component.
1 | import 'bootstrap-icons/font/bootstrap-icons.css'; |
Now, simply add the following HTML tag to load the icon.
1 2 3 4 5 6 | <p> You're <i className="bi bi-hand-index-thumb-fill" /> awesome! <i className="bi bi-emoji-heart-eyes" /> </p> |
4. Output
Let’s combine all code together and see how it looks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import React from 'react'; import 'bootstrap-icons/font/bootstrap-icons.css'; function App() { return ( <div className="App"> <b> Add bootstrap icons in React - <a href="https://www.cluemediator.com" target="_blank" rel="noopener"> Clue Mediator </a> </b><br /> <p> You're <i className="bi bi-hand-index-thumb-fill" /> awesome! <i className="bi bi-emoji-heart-eyes" /> </p> <p> Follow <i className="bi bi-heart-fill" style={{ color: '#fe251b' }} /> <span style={{ color: '#3b5998', fontWeight: 'bold' }}>Clue Mediator</span> <i className="bi bi-hand-thumbs-up-fill" style={{ color: '#3b5998' }} /> </p> </div> ); } export default App; |
Run the application and check the output in the browser.
I hope you find this article helpful.
Thank you for reading. Happy Coding..!! 🙂