How To Use Bootstrap Icons In Angular?
Last Updated :
29 Aug, 2024
The most popular framework for making responsive and mobile-friendly websites is called Bootstrap. They include forms, typography, buttons, tables, navigation, modals, and picture carousels etc.
These are built using CSS and HTML. It also supports plugins written in JavaScript. It provides the process of creating responsive designs.
What is a Bootstrap Icon?
Bootstrap icons are a set of symbols that you can use to represent actions on your website. Bootstrap icons are created using HTML, CSS, and JavaScript in combination. By doing this, developers can add visuals to their apps more quickly and easily than if they had to start from scratch. These icons are customizable as you can change their size, colour, and other properties in order to match your site's design.
Prerequisites
Approach
- Install Bootstrap and add Bootstrap CDN link in style.css file in your angular application.
- We will be making User Card in order to explain boostrap icons which will be opened up on clicking on + sign.
Steps to Use Bootstrap in Angular
Step 1: Create a New Angular Application
ng new bootstrap
Step 2: Install the required packages in your project using the following command.
npm install bootstrap bootstrap-icons
Folder Structure
Folder StructureDependencies
"dependencies": {
"@angular/animations": "^18.2.0",
"@angular/common": "^18.2.0",
"@angular/compiler": "^18.2.0",
"@angular/core": "^18.2.0",
"@angular/forms": "^18.2.0",
"@angular/platform-browser": "^18.2.0",
"@angular/platform-browser-dynamic": "^18.2.0",
"@angular/platform-server": "^18.2.0",
"@angular/router": "^18.2.0",
"@angular/ssr": "^18.2.0",
"bootstrap": "^5.3.3",
"bootstrap-icons": "^1.11.3",
"express": "^4.18.2",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.10"
}
Step 3: Import bootstrap icon in style.css file
@import "bootstrap-icons/font/bootstrap-icons.css";
Example:
Below is an example of adding bootstrap icons and action on icons(with dynamically change) in angular.
App Component
Below mentioned is code example demonstrating App Component having email,phone, location as information of user followed by app.component.css which helps in styling the User Card.
HTML
<!-- src/app/app.component.html -->
<div class="container mt-3">
<i (click)="toggleBox()" [ngClass]="{'bi-plus': !isBoxOpen, 'bi-dash': isBoxOpen}"
[ngStyle]="{'transform': isBoxOpen ? 'rotate(45deg)' : 'rotate(0deg)'}"></i>
<div class="card" style="width: 18rem;" *ngIf="isBoxOpen">
<div class="card-body">
<div class="d-flex align-items-center">
<i class="bi bi-person-circle me-3" style="font-size: 2rem;"></i>
<h5 class="card-title">{{ user.name }}</h5>
</div>
<p class="card-text">
<i class="bi bi-envelope-fill me-2"></i> {{ user.email }}
</p>
<p class="card-text">
<i class="bi bi-telephone-fill me-2"></i> {{ user.phone }}
</p>
<p class="card-text">
<i class="bi bi-geo-alt-fill me-2"></i> {{ user.location }}
</p>
<a href="#" class="btn btn-primary">
<i class="bi bi-person-lines-fill me-2"></i> Contact
</a>
</div>
</div>
</div>
CSS
/* src/app/app.component.css */
.card {
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.card-body {
padding: 20px;
}
.card-title {
margin: 0;
font-size: 1.5rem;
}
JavaScript
//src/app/app.component.ts
import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
@Component({
selector: 'app-root',
standalone: true,
imports: [RouterOutlet, CommonModule],
templateUrl: './app.component.html',
styleUrl: './app.component.css'
})
export class AppComponent {
title = 'bootstrap';
user = {
name: 'John Doe',
email: '[email protected]',
phone: '+1 234 567 890',
location: 'New York, USA'
};
isBoxOpen = false;
toggleBox() {
this.isBoxOpen = !this.isBoxOpen;
}
}
Output:
How To Use Bootstrap Icons In Angular?
Similar Reads
JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav
11 min read
Web Development Web development is the process of creating, building, and maintaining websites and web applications. It involves everything from web design to programming and database management. Web development is generally divided into three core areas: Frontend Development, Backend Development, and Full Stack De
5 min read
React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications
15+ min read
React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version
7 min read
JavaScript Interview Questions and Answers JavaScript is the most used programming language for developing websites, web servers, mobile applications, and many other platforms. In Both Front-end and Back-end Interviews, JavaScript was asked, and its difficulty depends upon the on your profile and company. Here, we compiled 70+ JS Interview q
15+ min read
Domain Name System (DNS) DNS is a hierarchical and distributed naming system that translates domain names into IP addresses. When you type a domain name like www.geeksforgeeks.org into your browser, DNS ensures that the request reaches the correct server by resolving the domain to its corresponding IP address.Without DNS, w
8 min read
NodeJS Interview Questions and Answers NodeJS is one of the most popular runtime environments, known for its efficiency, scalability, and ability to handle asynchronous operations. It is built on Chromeâs V8 JavaScript engine for executing JavaScript code outside of a browser. It is extensively used by top companies such as LinkedIn, Net
15+ min read
HTML Interview Questions and Answers HTML (HyperText Markup Language) is the foundational language for creating web pages and web applications. Whether you're a fresher or an experienced professional, preparing for an HTML interview requires a solid understanding of both basic and advanced concepts. Below is a curated list of 50+ HTML
14 min read
What is an API (Application Programming Interface) In the tech world, APIs (Application Programming Interfaces) are crucial. If you're interested in becoming a web developer or want to understand how websites work, you'll need to familiarize yourself with APIs. Let's break down the concept of an API in simple terms.What is an API?An API is a set of
10 min read
Top 10 Projects For Beginners To Practice HTML and CSS Skills Learning to code is an exciting journey, especially when stepping into the world of programming with HTML and CSSâthe foundation of every website you see today. For most beginners, these two building blocks are the perfect starting point to explore the creative side of web development, designing vis
8 min read