# Bare SVGs on the Web

Instructions for adding Font Awesome icons directly as SVG elements in your HTML.

> You can add icons as bare SVGs into your markup, but you'll need to do some heavy lifting to get them to fit in.

Make sure you:

- Grabbed some SVG code from an SVG file in a [Font Awesome Download](https://fontawesome.com/download), [Font Awesome package](/web/setup/packages.md), or any icons's details in our [icon search](https://fontawesome.com/icons)
- Are comfortable writing a little CSS

## SVG Formats

Font Awesome provides two different sets of SVG assets:

| Format   | What's the difference?                                                                                                                                          | Impact on Rendering                                                       |
| -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
| SVG      | SVG `viewbox` `width` is cropped to the edges of the interior symbol. The `viewbox` has a standard `height` based on the [Icon Canvas](/web/style/icon-canvas.md). | Icons will only take up as much space as their dimensions need.           |
| Full SVG | SVG `viewbox` `width` and `height` are set to a standard square based on the [Icon Canvas](/web/style/icon-canvas.md)                                              | Icons will be rendered at a consistent width with surrounding whitespace. |

## Basic Use

With the power of vectors, the browser can draw an SVG in no time flat. Just add the SVG code straight into your HTML.

Optionally, you can add [accessibility](/web/dig-deeper/accessibility.md) hints via `aria` attributes, or leave out the `xmlns` attribute which is [optional](https://developer.mozilla.org/en-US/docs/Web/SVG/Namespaces_Crash_Course#conclusion) in HTML5 documents.

<h3 style="display: flex; vertical-align: top;">
  <span style="padding-right: 10px;">What time is it...</span>
  <svg class="icon" aria-hidden="true" viewBox="0 0 512 512" style="width: 1em; height: 1em;"><path fill="currentColor" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200zm61.8-104.4l-84.9-61.7c-3.1-2.3-4.9-5.9-4.9-9.7V116c0-6.6 5.4-12 12-12h32c6.6 0 12 5.4 12 12v141.7l66.8 48.6c5.4 3.9 6.5 11.4 2.6 16.8L334.6 349c-3.9 5.3-11.4 6.5-16.8 2.6z"
 /></svg></h3>

```html
<div class="time-to-get-ill">
  <style>
    .icon {
      width: 1em;
      height: 1em;
      vertical-align: -0.125em;
    }
  </style>
  What time is it...
  <svg class="icon" aria-hidden="true" viewBox="0 0 512 512">
    <path
      d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200zm61.8-104.4l-84.9-61.7c-3.1-2.3-4.9-5.9-4.9-9.7V116c0-6.6 5.4-12 12-12h32c6.6 0 12 5.4 12 12v141.7l66.8 48.6c5.4 3.9 6.5 11.4 2.6 16.8L334.6 349c-3.9 5.3-11.4 6.5-16.8 2.6z" />
  </svg>
</div>
```

## Issues with Bare SVGs

### Make Sure to Add Some CSS

But one of the downsides to SVG sprites is that extra styling is necessary to make them behave when it comes to sizing and alignment. Our Font Awesome javascript normally handles this, but in this case you will need to handle this yourself.

Here's an example that limits the size and aligns an `.icon`:

```html
<!-- Simple styling to size an SVG -->
<style>
  .icon {
    width: 2em;
    height: 2em;
    vertical-align: -0.125em;
  }
</style>
```

### Visually Cropped Icons

Some icons may become visually cut off when using this method. This only occurs when all of the following are true:

- The [SVG](#svg-formats) files are used.
- An icon's height extends past the grid's height of our [Icon Canvas](/web/style/icon-canvas.md).

To avoid this issue, we recommend choosing one of the following:

#### Use the Full SVG Assets

The [Full SVG](#svg-formats) files include a viewbox contains the entire icon's path. If you must reference an SVG via the `<img>` element, use this format to avoid cropping portions of the icon that extend beyond the icon grid.

#### Use Inline SVG elements via `<svg>`

The [SVG](#svg-formats) files can be referenced inline via the `<svg>` element. You'll also need to include custom styling that adds `overflow: visible;`. Here's an example&hellip;

<div class="fa-3x" style="display: flex; gap: 0.5em; align-items: center;">
   <svg viewBox="0 0 576 512" style="width: 1em; fill: var(--wa-color-danger-on-quiet);">
    <path d="M41-24.9c-9.4-9.4-24.6-9.4-33.9 0S-2.3-.3 7 9.1l528 528c9.4 9.4 24.6 9.4 33.9 0s9.4-24.6 0-33.9l-96.4-96.4c2.7-2.4 5.4-4.8 8-7.2 46.8-43.5 78.1-95.4 93-131.1 3.3-7.9 3.3-16.7 0-24.6-14.9-35.7-46.2-87.7-93-131.1-47.1-43.7-111.8-80.6-192.6-80.6-56.8 0-105.6 18.2-146 44.2L41-24.9zM204.5 138.7c23.5-16.8 52.4-26.7 83.5-26.7 79.5 0 144 64.5 144 144 0 31.1-9.9 59.9-26.7 83.5l-34.7-34.7c12.7-21.4 17-47.7 10.1-73.7-13.7-51.2-66.4-81.6-117.6-67.9-8.6 2.3-16.7 5.7-24 10l-34.7-34.7zM325.3 395.1c-11.9 3.2-24.4 4.9-37.3 4.9-79.5 0-144-64.5-144-144 0-12.9 1.7-25.4 4.9-37.3L69.4 139.2c-32.6 36.8-55 75.8-66.9 104.5-3.3 7.9-3.3 16.7 0 24.6 14.9 35.7 46.2 87.7 93 131.1 47.1 43.7 111.8 80.6 192.6 80.6 37.3 0 71.2-7.9 101.5-20.6l-64.2-64.2z"/>
  </svg>

  <svg viewBox="0 0 576 512" style="width: 1em; margin-top: 0; overflow:visible;">
    <path d="M41-24.9c-9.4-9.4-24.6-9.4-33.9 0S-2.3-.3 7 9.1l528 528c9.4 9.4 24.6 9.4 33.9 0s9.4-24.6 0-33.9l-96.4-96.4c2.7-2.4 5.4-4.8 8-7.2 46.8-43.5 78.1-95.4 93-131.1 3.3-7.9 3.3-16.7 0-24.6-14.9-35.7-46.2-87.7-93-131.1-47.1-43.7-111.8-80.6-192.6-80.6-56.8 0-105.6 18.2-146 44.2L41-24.9zM204.5 138.7c23.5-16.8 52.4-26.7 83.5-26.7 79.5 0 144 64.5 144 144 0 31.1-9.9 59.9-26.7 83.5l-34.7-34.7c12.7-21.4 17-47.7 10.1-73.7-13.7-51.2-66.4-81.6-117.6-67.9-8.6 2.3-16.7 5.7-24 10l-34.7-34.7zM325.3 395.1c-11.9 3.2-24.4 4.9-37.3 4.9-79.5 0-144-64.5-144-144 0-12.9 1.7-25.4 4.9-37.3L69.4 139.2c-32.6 36.8-55 75.8-66.9 104.5-3.3 7.9-3.3 16.7 0 24.6 14.9 35.7 46.2 87.7 93 131.1 47.1 43.7 111.8 80.6 192.6 80.6 37.3 0 71.2-7.9 101.5-20.6l-64.2-64.2z"/>
  </svg>
</div>

```html
<div>
  <!-- eye-slash icon - without fix  -->
  <svg viewBox="0 0 576 512">
    <path
      d="M41-24.9c-9.4-9.4-24.6-9.4-33.9 0S-2.3-.3 7 9.1l528 528c9.4 9.4 24.6 9.4 33.9 0s9.4-24.6 0-33.9l-96.4-96.4c2.7-2.4 5.4-4.8 8-7.2 46.8-43.5 78.1-95.4 93-131.1 3.3-7.9 3.3-16.7 0-24.6-14.9-35.7-46.2-87.7-93-131.1-47.1-43.7-111.8-80.6-192.6-80.6-56.8 0-105.6 18.2-146 44.2L41-24.9zM204.5 138.7c23.5-16.8 52.4-26.7 83.5-26.7 79.5 0 144 64.5 144 144 0 31.1-9.9 59.9-26.7 83.5l-34.7-34.7c12.7-21.4 17-47.7 10.1-73.7-13.7-51.2-66.4-81.6-117.6-67.9-8.6 2.3-16.7 5.7-24 10l-34.7-34.7zM325.3 395.1c-11.9 3.2-24.4 4.9-37.3 4.9-79.5 0-144-64.5-144-144 0-12.9 1.7-25.4 4.9-37.3L69.4 139.2c-32.6 36.8-55 75.8-66.9 104.5-3.3 7.9-3.3 16.7 0 24.6 14.9 35.7 46.2 87.7 93 131.1 47.1 43.7 111.8 80.6 192.6 80.6 37.3 0 71.2-7.9 101.5-20.6l-64.2-64.2z" />
  </svg>

  <!-- eye-slash icon - with fix  -->
  <svg viewBox="0 0 576 512" style="overflow:visible;">
    <path
      d="M41-24.9c-9.4-9.4-24.6-9.4-33.9 0S-2.3-.3 7 9.1l528 528c9.4 9.4 24.6 9.4 33.9 0s9.4-24.6 0-33.9l-96.4-96.4c2.7-2.4 5.4-4.8 8-7.2 46.8-43.5 78.1-95.4 93-131.1 3.3-7.9 3.3-16.7 0-24.6-14.9-35.7-46.2-87.7-93-131.1-47.1-43.7-111.8-80.6-192.6-80.6-56.8 0-105.6 18.2-146 44.2L41-24.9zM204.5 138.7c23.5-16.8 52.4-26.7 83.5-26.7 79.5 0 144 64.5 144 144 0 31.1-9.9 59.9-26.7 83.5l-34.7-34.7c12.7-21.4 17-47.7 10.1-73.7-13.7-51.2-66.4-81.6-117.6-67.9-8.6 2.3-16.7 5.7-24 10l-34.7-34.7zM325.3 395.1c-11.9 3.2-24.4 4.9-37.3 4.9-79.5 0-144-64.5-144-144 0-12.9 1.7-25.4 4.9-37.3L69.4 139.2c-32.6 36.8-55 75.8-66.9 104.5-3.3 7.9-3.3 16.7 0 24.6 14.9 35.7 46.2 87.7 93 131.1 47.1 43.7 111.8 80.6 192.6 80.6 37.3 0 71.2-7.9 101.5-20.6l-64.2-64.2z" />
  </svg>
</div>
```
