Skip to main content
React Icons provides powerful styling capabilities through the IconContext API, allowing you to set default styles for all icons within a component tree.

IconContext Provider

The IconContext.Provider lets you configure default props for all icons in its subtree.

Basic Usage

Available Context Options

The IconContext interface supports the following properties:

Global Styling Patterns

Set a consistent color scheme:

Inline Global Styling

Use the style property in IconContext for inline CSS:
The style property in IconContext can override both size and color properties when specified.

Nesting Contexts

You can nest multiple IconContext.Provider components to create hierarchical styles:

Overriding Context Styles

Individual icon props always override context values:
1

Context sets defaults

The IconContext.Provider establishes base styles
2

Icons inherit styles

All icons within the provider inherit these defaults
3

Props override context

Individual icon props take precedence over context values

CSS Class Merging

When both context and individual icons have className, they are merged:
The context className comes first, followed by the individual className. This affects CSS specificity.

Vertical Alignment Fix

From version 3+, vertical-align: middle is not applied by default. Use IconContext to add it globally:

Advanced: Dynamic Theming

Create theme-aware icon styling:

SVG Attributes via Context

Set default SVG attributes for all icons:
The attr property is overwritten by other attributes like style, color, and direct SVG props.

Best Practices

Apply IconContext.Provider at the root or layout level to ensure consistent icon styling across your application.
Using className with CSS files provides better performance and maintainability than inline styles.
Establish and document icon sizing and color conventions for your team to maintain visual consistency.
Be mindful of where your IconContext.Provider boundaries are, especially in component libraries or shared components.

Next Steps

Customizing Icons

Learn about individual icon customization

Performance

Optimize bundle size and rendering performance