Skip to main content
The IconContext allows you to set default properties for all icons within your application or a specific component tree using React’s Context API.

Overview

Instead of passing the same props to every icon component, you can use IconContext.Provider to set defaults that apply to all icons within its scope.

Basic Usage

IconContext Interface

The IconContext accepts the following properties:

Property Reference

The default size of 1em means icons scale with the font size of their parent element.

Configuration Examples

Global Icon Styling

Set consistent styling across your entire application:

Theme-Based Icons

Using className for Global Styling

Combine className with CSS for consistent icon styling:

Using style for Inline Styling

Apply inline styles to all icons:

Nested Contexts

You can nest multiple IconContext.Provider components. Inner contexts override outer ones:

Override Context Props

Props passed directly to icon components override context values:

Priority Order

When multiple sources define the same property, React Icons applies them in this order (highest priority first):
  1. Direct props - Props passed directly to the icon component
  2. Nested context - The closest IconContext.Provider in the component tree
  3. Parent context - Outer IconContext.Provider components
  4. Default values - Library defaults (size: '1em', color: currentColor)

Real-World Examples

Button Components

Card Components

Advanced: Using attr for SVG Attributes

The attr property allows you to pass custom SVG attributes to all icons:

TypeScript Support

The IconContext is fully typed:
See the TypeScript guide for complete type definitions and advanced TypeScript usage.

Best Practices

Use Context for Consistent Styling

Scope Contexts Appropriately

Use className for CSS-Based Styling

Requirements

The IconContext requires React 16.3 or higher because it uses the React Context API.

Next Steps

Icon Imports

Learn about importing icons from different packs

TypeScript

Explore TypeScript types and interfaces