Font Awesome 7

repository·7.x·Indexed 13 days ago

https://github.com/fortawesome/font-awesome

A comprehensive icon library and toolkit for web and desktop applications, providing icons via SVG with JavaScript, web fonts, and desktop fonts. Version 7 includes support for multiple icon families (Classic, Duotone, Sharp), Power Transforms via data-fa-transform, icon masking, and a wide array of sizing and animation CSS classes. Available as a set of NPM packages including @fortawesome/fontawesome-free and @fortawesome/fontawesome-svg-core.

Tokens
98.5K
Snippets
394
Records
445
Agent score
96%

What's inside Font Awesome

  1. Understand the contents of @fortawesome/fontawesome-free

    7.x

    The @fortawesome/fontawesome-free package contains all files available through the Free and Pro CDNs, organized into the following directories:

    • /js: All JavaScript files for the SVG with JS implementation.
    • /css: All CSS files for the Web Fonts with CSS implementation.
    • /sprites: SVG icons packaged in a sprite format.
    • /scss: SCSS pre-processor files for the Web Fonts with CSS implementation.
    • /webfonts: Accompanying files required for Web Fonts with CSS.
    • /svg: Individual icon files in SVG format.
  2. Understand Font Awesome versioning and breaking changes

    7.x

    Font Awesome follows Semantic Versioning (<major>.<minor>.<patch>), but version 7 deviates from standard SemVer in the following ways:

    • Design Changes: Any release may update the design, look-and-feel, or branding of an existing icon.
    • Backward Compatibility: Patch versions will never intentionally break backward compatibility. However, minor releases may include backward-incompatible changes (check UPGRADING.md for instructions).
    • Icon Retention: A minor or patch release will never remove icons.
    • Bug Fixes: Bug fixes are typically patch releases, but if they require backward-incompatible changes, they are released as minor versions.
  3. How to use common Font Awesome types in TypeScript

    7.x

    While @fortawesome/fontawesome-common-types contains the shared definitions used across Font Awesome 7 JavaScript packages, you should not import types directly from this package. Instead, all types are re-exported through the main @fortawesome/fontawesome-svg-core package. To ensure compatibility and follow best practices, always import your types from @fortawesome/fontawesome-svg-core.

    import {
      IconName
    } from `@fortawesome/fontawesome-svg-core`
    
    const myIcon: IconName = "..."
  4. How the icon-to-SVG (i2svg) replacement works

    7.x

    Font Awesome uses a mutation-based approach to transform HTML icon elements into SVGs.

    1. Detection: The observe(options) function uses a MutationObserver to watch for new nodes or attribute changes (like class updates) in the DOM.
    2. Parsing: When a candidate node is found, parseMeta(node) extracts the prefix, iconName, transform, and extra attributes (styles, classes, etc.).
    3. Mutation: Depending on the configuration (config.autoReplaceSvg), the library uses either the replace mutator (which removes the original node and inserts an SVG) or the nest mutator (which replaces the node's inner HTML with the SVG).
    4. Rendering: The render(iconDefinition) function generates the abstract SVG structure, which is then converted into real DOM elements via convertSVG.