Font Awesome图标为何以SVG格式渲染?Angular5项目动画异常问题
Hey, let's get to the bottom of why your Font Awesome icons are showing up as SVG and losing that pulse animation in your Angular 5 project. This usually happens because of conflicting SVG tools in your project or incorrect CSS setup. Here's how to fix it step by step:
1. Make Sure Font Awesome CSS is Properly Loaded
First, double-check that the Font Awesome CSS is being pulled into your project correctly—this is the most common fix:
- Open your
angular.json(or.angular-cli.jsonif you're on the older Angular CLI version) and find thestylesarray under your app configuration. - Add the path to Font Awesome's minified CSS:
"styles": [ "node_modules/font-awesome/css/font-awesome.min.css", "src/styles.css" ] - Restart your Angular dev server after making this change—this ensures the CSS gets bundled and loaded properly.
2. Check for SVG Icon Conflicts
If you're using tools like Angular Material's MatIconModule, it might be automatically converting your <i> tags to SVG elements without you realizing it. Here's how to handle that:
- Temporarily remove
MatIconModulefrom yourapp.module.tsimports and test if the icons go back to normal. If they do, that's the source of the conflict. - To keep MatIcon and Font Awesome working together, add the
mat-icon-no-colorclass to your Font Awesome<i>tags, or configure MatIcon to ignore thefaclass prefix so it doesn't hijack those elements.
3. Force Browser to Use Font Icons Instead of SVG
Sometimes browsers prioritize SVG over font icons if they detect both. Add this CSS to your global styles.css to enforce font rendering:
.fa { font-family: 'FontAwesome' !important; speak: none; font-style: normal; font-weight: normal; font-variant: normal; text-transform: none; line-height: 1; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } /* Re-enable the pulse animation explicitly */ .fa-pulse { -webkit-animation: fa-spin 1s infinite steps(8); animation: fa-spin 1s infinite steps(8); }
4. Uninstall Conflicting Font Awesome 5+ Dependencies
If you accidentally installed the newer Font Awesome Angular components (like @fortawesome/angular-fontawesome), they'll force SVG rendering and clash with your 4.7.0 version. Clean those up:
- Run these commands to uninstall the conflicting packages:
npm uninstall @fortawesome/angular-fontawesome @fortawesome/fontawesome-svg-core @fortawesome/free-solid-svg-icons - Then wipe your
node_modulesand lock file to start fresh:rm -rf node_modules package-lock.json npm install
5. Verify the Fix
After trying these steps, open Chrome DevTools to confirm:
- Check your
<i>icon element—itsfont-familyshould be set toFontAwesome, and it shouldn't be an SVG element. - Inspect the
fa-pulseclass to make sure the animation properties are applied and not overridden by other CSS.
内容的提问来源于stack exchange,提问作者Present practice

