Bootstrap Icons - Methods & Styling Patterns

Working examples demonstrating icon usage methods, sizing, coloring, and alignment techniques.

Icon Fonts (Primary Method)

Use <i class="bi bi-*"> for icon fonts. This is the recommended method for most use cases due to simplicity and automatic sizing with text.

Basic Usage

bi-alarm
bi-heart-fill
bi-check-circle
bi-star

Class Naming Convention

Icons use bi bi-{name} pattern. Add -fill suffix for filled variants.

Outline
Filled
Outline
Filled

External Image Method

Reference icon SVG files directly via <img> element. Ideal for email templates, static pages, and content management systems where CSS/font dependencies should be avoided.

Via CDN

Reference icons directly from jsDelivr CDN.

Heart heart-fill (32x32)
Star star-fill (32x32)
Check check-circle-fill (32x32)

Size Variations

Envelope 16x16
Envelope 24x24
Envelope 32x32
Envelope 48x48

CSS Method

Include icons via CSS background-image or mask-image. Useful for decorative icons applied via CSS classes without markup changes.

Background-image Approach

Icons display as background images with fixed colors. Cannot inherit text color.

icon-css-bg-heart
icon-css-bg-star
icon-css-bg-check

Mask Approach (Inherits currentColor)

Icons inherit the parent's text color via currentColor. Requires vendor prefixes for Safari (-webkit-mask-*).

text-danger parent
text-warning parent
text-success parent

Color Inheritance Demonstration

Same icon class with different parent text colors.

text-primary
text-secondary
text-success
text-danger

Sizing Variations

Icons scale with font-size. Use inline styles, Bootstrap utilities, or custom CSS classes.

Inline Style Sizing

16px
24px
32px
2rem
3rem

Bootstrap Font Size Utilities

Use .fs-1 through .fs-6 utilities for consistent sizing.

fs-1
fs-2
fs-3
fs-4
fs-5
fs-6

Custom CSS Classes

Define reusable size classes: .icon-lg, .icon-md, .icon-sm.

icon-lg
icon-md
icon-sm

Coloring Techniques

Icons inherit text color. Use Bootstrap utilities, inline styles, or CSS classes.

Bootstrap Text Utilities

text-primary
text-secondary
text-success
text-danger
text-warning
text-info

Inline Color Styles

#ff6b6b
#4ecdc4
#ffe66d
#95e1d3

currentColor Inheritance

Icons automatically inherit the parent element's text color.

Parent is text-primary
Parent is text-danger
Parent is text-success

Vertical Alignment

Icons may need alignment adjustments when placed inline with text.

Bootstrap Alignment Utilities

align-baseline
align-middle
align-text-bottom
align-text-top

CSS Vertical Centering Fix

Use vertical-align: -0.125em for precise baseline alignment with text.

Aligned with -0.125em
Default alignment

Embedded SVG

Copy SVG code directly from icons.getbootstrap.com for maximum control. Uses currentColor for automatic color inheritance.

Basic SVG Embedding

Embedded SVG (32x32)

SVG Sizing with width/height Attributes

16x16
24x24
32x32
48x48

SVG with fill Attribute

fill="#0d6efd"
fill="#dc3545"
fill="#198754"

SVG Sprite

Define icons once as symbols, reference multiple times with <use>. Ideal for pages with many repeated icons.

Internal Sprite Reference

Reference symbols defined in the same document with <use href="#id">.

href="#icon-heart"
href="#icon-star"
href="#icon-check"

Colored Sprite Icons

text-danger parent
text-warning parent
text-success parent

External Sprite Reference (Syntax)

Reference an external sprite file with <use href="path/bootstrap-icons.svg#icon-name">.

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

Combined Patterns

Practical examples combining sizing, coloring, and alignment techniques.

Status Indicators

Success
Warning
Error
Info

Icons in Different Contexts

Inline with body text (inherits size)

Inline with heading (inherits size)

Inline with small text (inherits size)