Magento2 Font Awesome – How to Add Using Library

font-awesomelibrarymagento2

in my case, I have added this font awesome by declaring it in the header.

is there any way to inject this font awesome by libraries on the resource of my module and not call it externally by link

Best Answer

  1. You need to download the fontawesome zip package and add the required css files under your theme. Steps to add the CSS files in your theme:
  • Go to directory app/design/frontend/YourVendor/YourTheme/web/css .
  • Unzip the downloaded fontawesome zip package under fontawesome directory.
  1. To include/call a CSS file, add the <css src="..." /> block in section in a layout file. app/design/frontend/YourVendor/YourTheme/Magento_Theme/layout/default_head_blocks.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <css src="css/all.css" rel="stylesheet" type="text/css" />
        <css src="css/fontawsome.css" rel="stylesheet" type="text/css" />
    </head>
</page>
  1. Deploy your static resources (Theme changes):
  • php bin/magento setup:upgrade
  • php bin/magento setup:static-content:deploy -f
  • php bin/magento cache:flush

Now check your css file will be added on your website.

Related Topic