Font Awesome 7 Shims for Legacy Icon Name Support: Complete Implementation Guide
Font Awesome 7 shims automatically translate legacy Font Awesome 4 class names to modern icons, enabling zero-code-change upgrades for existing projects.
Font Awesome 7 shims serve as a critical compatibility layer for development teams maintaining legacy codebases. This system maps deprecated icon identifiers—such as fa-arrow-circle-o-down—to their modern equivalents like fa-circle-down, ensuring visual consistency without requiring HTML or CSS modifications. As implemented in the FortAwesome/Font-Awesome repository, the shim architecture combines YAML-based metadata with runtime JavaScript translation.
What Are Font Awesome 7 Shims?
Font Awesome 7 shims are a backward-compatibility mechanism designed to handle the breaking changes introduced between Font Awesome 4 and modern versions. When you include the shim layer in your project, the library intercepts legacy fa-* class names and substitutes the appropriate Font Awesome 7 icon and style prefix.
The system supports both JavaScript and CSS-only implementations, making it adaptable to diverse project architectures—from static HTML sites to complex React applications.
How the Shim Architecture Works
The Font Awesome 7 shim system operates through three coordinated components: a canonical mapping definition, a JavaScript runtime loader, and a CSS compilation layer.
The Mapping Source (metadata/shims.yml)
The authoritative source of truth for all legacy-to-modern translations lives in metadata/shims.yml. This YAML file defines every supported legacy name alongside its modern replacement and required style prefix.
arrow-circle-o-down:
prefix: far
name: circle-down
During the build process, this file generates the runtime arrays used by both JavaScript and CSS implementations. The mapping includes hundreds of legacy icons, covering the complete Font Awesome 4 nomenclature.
JavaScript Runtime Registration (js/v4-shims.js)
The js/v4-shims.js file registers the mapping with the Font Awesome runtime through the global ___FONT_AWESOME___ namespace. The script contains a generated shims array and initialization logic:
var shims = [
["glass", null, "martini-glass-empty"],
["envelope-o", "far", "envelope"],
["arrow-circle-o-down", "far", "circle-down"],
// ... additional mappings
];
bunker(function () {
if (typeof namespace.hooks.addShims === 'function') {
namespace.hooks.addShims(shims);
} else {
namespace.shims.push.apply(namespace.shims, shims);
}
});
The code checks for the presence of an addShims hook on the namespace object. If available, it uses the formal API; otherwise, it directly extends the namespace.shims array. This defensive coding ensures compatibility across different Font Awesome 7 loading scenarios.
CSS Fallback (scss/v4-shims.scss)
For projects that rely solely on CSS without JavaScript, scss/v4-shims.scss provides a Sass-based entry point:
@use 'functions';
@use 'variables' as v;
@use 'shims';
This file imports the necessary functions and variables, then generates compiled CSS that contains the legacy selectors. The resulting stylesheet allows browsers to render old class names correctly through CSS pseudo-elements and font-family declarations, without requiring JavaScript execution.
Implementing Font Awesome 7 Shims in Your Project
You can activate legacy icon support through two primary methods depending on your project's JavaScript requirements.
JavaScript Shim Installation
Include the v4-shims script after your main Font Awesome 7 JavaScript file:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.2.0/css/all.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.2.0/js/v4-shims.min.js"></script>
<i class="fa fa-arrow-circle-o-down"></i> <!-- renders as fa-circle-down -->
The shim script registers itself immediately upon loading, intercepting DOM observations and replacing legacy icons before they render.
CSS-Only Shim Installation
For static sites or performance-critical applications avoiding JavaScript:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.2.0/css/v4-shims.min.css">
<i class="fa fa-arrow-circle-o-down"></i> <!-- works without JavaScript -->
This approach relies on the compiled CSS selectors in v4-shims.css to handle the translation, though it offers less flexibility than the JavaScript implementation for dynamic content.
React and Component Frameworks
When using the official Font Awesome React library, import the shim module to register mappings before rendering components:
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import '@fortawesome/fontawesome-free/js/v4-shims'; // registers shims globally
export default function LegacyComponent() {
return (
<FontAwesomeIcon icon="arrow-circle-o-down" />
);
}
The shim integrates with the React component's icon lookup logic, ensuring that legacy name strings passed to the icon prop resolve to the correct SVG paths.
Technical Deep Dive: Runtime Lookup Process
When Font Awesome 7 parses a class list or icon reference, the resolution follows a specific fallback chain:
- Primary Lookup: The system first attempts to resolve the provided name against the Font Awesome 7 icon registry using the specified prefix (
fas,far, etc.). - Shim Consultation: If the primary lookup fails, the runtime checks the
namespace.shimsarray populated byjs/v4-shims.js. - Translation: A matching legacy name triggers substitution of the new icon name and optional style prefix (e.g., converting
fatofar). - Rendering: The DOM receives the correct
<svg>element or CSS pseudo-element representing the modern icon.
This process is transparent to developers and applies to both static HTML and dynamically injected content observed by the Font Awesome mutation watcher.
Summary
- Font Awesome 7 shims provide automatic translation of Font Awesome 4 class names to modern equivalents without requiring HTML changes.
- The mapping definitions reside in
metadata/shims.yml, which generates runtime data for both JavaScript and CSS implementations. - Include
js/v4-shims.jsfor dynamic JavaScript applications orscss/v4-shims.scss(compiled to CSS) for static sites. - The system uses the global
___FONT_AWESOME___namespace andaddShimshook to register legacy mappings at runtime. - React and modern frameworks support shims through simple module imports that execute the registration code before component rendering.
Frequently Asked Questions
Do I need to modify my existing HTML to use Font Awesome 7 shims?
No. The shim system is specifically designed to avoid HTML modifications. By loading v4-shims.js or v4-shims.css, your existing fa-arrow-circle-o-down and similar classes continue functioning while rendering the modern equivalent icons. This allows incremental migration without touching legacy templates.
What is the performance impact of using v4-shims.js?
The performance overhead is minimal. The shim file is lightweight (typically under 5KB minified) and executes once during initialization to populate the namespace.shims array. The lookup overhead during icon resolution is a simple array check that occurs only when a primary icon lookup fails, adding negligible latency to the rendering pipeline.
Can I use Font Awesome 7 shims with frameworks like React or Vue?
Yes. Import @fortawesome/fontawesome-free/js/v4-shims or the npm package equivalent in your application's entry point before rendering icons. The shim registers globally with the Font Awesome library, ensuring that components using legacy icon names receive the correct SVG definitions. This works identically across React, Vue, Angular, and other component-based architectures.
Where are the shim mappings defined in the source code?
The canonical definitions live in metadata/shims.yml in the FortAwesome/Font-Awesome repository. This YAML file is the single source of truth that generates the JavaScript shim arrays in js/v4-shims.js and the CSS selectors compiled from scss/v4-shims.scss. If you need to inspect specific legacy-to-modern mappings, consult this file directly.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →