PHPackages                             husseinalhammad/fontawesome-svg - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. husseinalhammad/fontawesome-svg

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

husseinalhammad/fontawesome-svg
===============================

PHP class to add Font Awesome 5+'s SVG icons inline without Javascript.

v1.3.0(2y ago)1811.3k↓38.6%4[3 issues](https://github.com/husseinalhammad/FontAwesomeSVG-PHP/issues)MITPHPPHP &gt;=5.3.0CI failing

Since May 17Pushed 2y ago4 watchersCompare

[ Source](https://github.com/husseinalhammad/FontAwesomeSVG-PHP)[ Packagist](https://packagist.org/packages/husseinalhammad/fontawesome-svg)[ Docs](https://github.com/husseinalhammad/FontAwesomeSVG-PHP)[ RSS](/packages/husseinalhammad-fontawesome-svg/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (5)Used By (0)

Font Awesome SVG - PHP
======================

[](#font-awesome-svg---php)

A PHP class that can be used to add [Font Awesome 6+](https://fontawesome.com/)'s SVG icons inline without Javascript.

Installation
------------

[](#installation)

You can install it using Composer:

```
composer require husseinalhammad/fontawesome-svg

```

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

Usage
-----

[](#usage)

### Files

[](#files)

- 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)

### Examples

[](#examples)

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

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

Add custom classes:

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

Remove default class `.svg-inline--fa`:

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

Change `` fill (default is `currentColor`):

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

Add ``:

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

Multiple options at once:

```
echo $FA->get_svg('fa-solid fa-file', [
    'class' => 'my-custom-class another-class',
    'default_class' => false,
    'title' => 'My title',
    'role' => 'img',
    'fill' => '#ffffff',
]);
```

Customise duotone icons:

```
echo $FA->get_svg('fa-duotone fa-laugh-wink', [
    'primary' => [
        'fill'    => '#e64980',
    ],
    'secondary' => [
        'fill'    => '#fcc417',
        'opacity' => '1',
    ],
]);
```

OptionWhat it meansclassAdds classes to the SVG tagdefault\_classIf set to `false`, the default CSS class won't be added to the SVG tag. Deafult: `true`.inline\_styleWhether to add duotone styles as inline style to the `` tag. Deafult: `true`.titleAdds a `` inside the SVG tag for semantic iconstitle\_idAdds an `id` attribute to `` and adds `aria-labelledby` on the SVG tag with the same valueroleThe value of the `role` attribute in the SVG tag. Default: `img`fillThe value of the `fill` attribute in the `` inside the SVG. Default: `currentColor`primaryDuotone primary options (see table below)secondaryDuotone secondary options (see table below)Duotone
-------

[](#duotone)

> Requires **v5.10.0** or greater, and a FontAwesome Pro license

Sharp
-----

[](#sharp)

> Requires **v6.4.0** or greater, and a FontAwesome Pro license

```
echo $FA->get_svg('fa-sharp fa-light fa-file');
echo $FA->get_svg('fa-sharp fa-regular fa-file');
echo $FA->get_svg('fa-sharp fa-solid fa-file');
```

### options

[](#options)

If `inline_style` is enabled, the value of `fill` and `opacity` are also used in the inline style on `` tag.

OptionWhat it meansfillThe value of the `fill` attribute in the `` inside the SVG. Default: `currentColor`opacityThe value of the `opacity` attribute in the `` inside the SVG.### Examples:

[](#examples-1)

Single colour:

```
echo $FA->get_svg('fad fa-laugh-wink', [
    'fill' => '#e64980',
]);
```

Swapping Layer Opacity:

```
echo $FA->get_svg('fad fa-laugh-wink', [
    'fill'  => '#e64980',
    'class' => 'fa-swap-opacity',
]);
```

Single colour with custom opacity:

```
echo $FA->get_svg('fad fa-laugh-wink', [
    'fill' => '#e64980',
    'secondary' => [
        'opacity' => '0.2',
    ],
]);
```

Custom colours and opacity:

```
echo $FA->get_svg('fad fa-laugh-wink', [
    'primary' => [
        'fill'    => '#e64980',
        'opacity' => '0.5',
    ],
    'secondary' => [
        'fill'    => '#fcc417',
        'opacity' => '1',
    ],
]);
```

Aliases
-------

[](#aliases)

The short aliases from version 5 are still supported

```
echo $FA->get_svg('fab fa-twitter');
echo $FA->get_svg('fad fa-file');
echo $FA->get_svg('fal fa-file');
echo $FA->get_svg('far fa-file');
echo $FA->get_svg('fas fa-file');

// And the new shorthands for thin and sharp
echo $FA->get_svg('fat fa-file'); // thin
echo $FA->get_svg('fasl fa-file'); // sharp-light
echo $FA->get_svg('fasr fa-file'); // sharp-regular
echo $FA->get_svg('fass fa-file'); // sharp-solid
```

Accessibility
-------------

[](#accessibility)

The below is implemented based on:

- Font Awesome's [Accessibility docs](https://fontawesome.com/how-to-use/on-the-web/other-topics/accessibility)
- Heather Migliorisi's article on CSS-Tricks [Accessible SVGs](https://css-tricks.com/accessible-svgs/)

### `role` attribute

[](#role-attribute)

`role="img"` is added to the SVG tag by default:

```

```

### ``, `aria-labelledby`

[](#title-aria-labelledby)

You can set a ``, an `id` for the `` and the `aria-labelledby` attribute will be added automatically:

```
echo $FA->get_svg('fa-solid fa-file', [
    'title' => 'File',
    'title_id' => 'file-id',
]);
```

```

  File

```

### `aria-*` attributes

[](#aria--attributes)

You can add any aria-\* attribute to the SVG tag:

```
echo $FA->get_svg('fa-solid fa-file', [
    'aria-label' => 'File',
]);
```

```

```

### `aria-hidden` attribute

[](#aria-hidden-attribute)

`aria-hidden="true"` is added to the SVG tag by default unless `` (and `aria-labelledby`) or `aria-label` is set.

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

```

```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~626 days

Total

4

Last Release

1044d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/51f15ca8f84804918c428a794f99e6f22fc92fd18827ecc5b9f0cb539a693a3b?d=identicon)[husseinalhammad](/maintainers/husseinalhammad)

---

Top Contributors

[![husseinalhammad](https://avatars.githubusercontent.com/u/8544092?v=4)](https://github.com/husseinalhammad "husseinalhammad (26 commits)")

---

Tags

fontawesomephpsvgsvgFontAwesome

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/husseinalhammad-fontawesome-svg/health.svg)

```
[![Health](https://phpackages.com/badges/husseinalhammad-fontawesome-svg/health.svg)](https://phpackages.com/packages/husseinalhammad-fontawesome-svg)
```

###  Alternatives

[components/flag-icon-css

A curated collection of all country flags in SVG — plus the CSS for easier integration.

12.0k1.6M23](/packages/components-flag-icon-css)[twbs/bootstrap-icons

Official open source SVG icon library for Bootstrap

7.9k2.0M56](/packages/twbs-bootstrap-icons)[simple-icons/simple-icons

SVG icons for popular brands

24.8k194.2k4](/packages/simple-icons-simple-icons)[rinvex/countries

Rinvex Countries is a simple and lightweight package for retrieving country details with flexibility. A whole bunch of data including name, demonym, capital, iso codes, dialling codes, geo data, currencies, flags, emoji, and other attributes for all 250 countries worldwide at your fingertips.

1.7k7.4M48](/packages/rinvex-countries)[kartik-v/bootstrap-star-rating

A simple yet powerful JQuery star rating plugin for Bootstrap.

1.1k4.5M5](/packages/kartik-v-bootstrap-star-rating)[lipis/flag-icons

A curated collection of all country flags in SVG — plus the CSS for easier integration.

12.0k27.5k4](/packages/lipis-flag-icons)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
