Add inline SVG Font Awesome icons in PHP
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Font Awesome SVG - PHP

A PHP class that can be used to add Font Awesome 5+'s SVG icons inline without Javascript.


You can install it using Composer:

composer require husseinalhammad/fontawesome-svg

Or you can download the FontAwesomeSVG.php file and include it manually.



  • Download Font Awesome (Free or Pro)
  • Get the folder advanced-options/raw-svg and place it in your project
  • Add svg-with-js/css/fa-svg-with-js to your document (or write your own CSS)


// $dir = directory where SVG files are
$FA = new FontAwesomeSVG($dir);

echo $FA->get_svg('fas fa-file');

Add custom classes:

echo $FA->get_svg('fas fa-file', ['class' => 'my-custom-class another-class']);

Remove default class .svg-inline--fa:

echo $FA->get_svg('fas fa-file', ['default_class' => false]);

Change <path> fill (default is currentColor):

echo $FA->get_svg('fas fa-file', ['fill' => '#f44336']);

Add <title></title>:

echo $FA->get_svg('fas fa-file', ['title' => 'My accessible icon']);

Multiple options at once:

echo $FA->get_svg('fas fa-file', [
    'class' => 'my-custom-class another-class',
    'default_class' => false,
    'title' => 'My title',
    'role' => 'img',
    'fill' => '#ffffff',
Option What it means
class Adds classes to the SVG tag
default_class If set to false, the default CSS class won't be added to the SVG tag. Deafult: true.
title Adds a <title> inside the SVG tag for semantic icons
role The value of the role attribute in the SVG tag. Default: img
fill The value of the fill attribute in the <path> inside the SVG. Default: currentColor


  • role="img" is added to the SVG tag by default
  • aria-hidden="true" is added to the SVG tag by default unless a <title> is set