Stylesheet definitions required to properly display icons generated by the API in the DOM.
Generates the accompanying CSS that is necessary to correctly display icons. If
you choose to disable autoAddCss in the configuration you'll need to grab
these styles and insert them manually into the DOM.
As of Version 5.7.0, this method also supports the Promise API:
dom.i2svg().then(function(){
console.log('Icons have rendered')})
You can also use callbacks that will be triggered when the icons have been rendered:
functioniconDoneRendering(){
console.log('Icons have rendered')}
dom.i2svg({callback: iconsDoneRendering })
dom.insertCss()
Convenience method that will add the given CSS to the DOM <head>.
import{ dom }from'@fortawesome/fontawesome-svg-core'const css = dom.css()
dom.insertCss(css)
dom.watch(params)
Calls dom.i2svg() for you and watches the DOM for any additional icons being added or modified.
Different default configs
DOM watching is on by default when Font Awesome is loaded from @fortawesome/fontawesome-free or @fortawesome/fontawesome-pro but it's disabled for the @fortawesome/fontawesome-svg-core.
This method is useful when you're loading @fortawesome/fontawesome-svg-core, but would still like to leverage automatic DOM watching.
Params
Calling dom.watch() without params is equivalent to calling with the following params:
const faPlusIcon =icon(faPlus)// Get the first element out of the HTMLCollection
document.appendChild(faPlusIcon.node[0])
Abstract tree:
icon(faPlus).abstract
[{"tag":"svg","attributes":{"data-prefix":"fas","data-icon":"user","class":"svg-inline--fa fa-user fa-w-16","role":"img","xmlns":"http://www.w3.org/2000/svg","viewBox":"0 0 512 512"},"children":[{"tag":"path","attributes":{"fill":"currentColor","d":"M96…112z"}}]}]// The `data-prefix` attribute will only accept short prefix names (ex. fas, far, fal, fat, fad, fass)
"Marty, you're not thinking fourth-dimensionally!"
The abstract value is mostly useful for library / framework / tooling creators. It provides a data structure that can easily be converted into other objects.
Using a transform:
icon(faPlus,{transform:{size:8,// starts at 16 so make it halfx:-4,// the same as left-4y:6,// the same as up-6rotate:90,// the same as rotate-90flipX:true,// the same as flip-hflipY:true// the same as flip-v}}).html
More than meets the eye...
If you need help figuring out transforms, see parse.transform.
Use the main icon as a mask for another another icon:
Pre-registering icon definitions so that do not have to explicitly pass them to render an icon.
Explicitly passing the icon
import{ icon }from'@fortawesome/fontawesome-svg-core'import{ faUser }from'@fortawesome/free-solid-svg-icons'import{ fab }from'@fortawesome/free-brands-svg-icons'icon(faUser)icon(fab.faFortAwesome)
Using the library
import{ icon, library }from'@fortawesome/fontawesome-svg-core'import{ faUser }from'@fortawesome/free-solid-svg-icons'import{ fab }from'@fortawesome/free-brands-svg-icons'
library.add(fab, faUser)icon({prefix:'fas',iconName:'user'})icon({prefix:'fab',iconName:'fort-awesome'})
parse.icon(icon)
Takes an icon string, an object, or an array and returns an icon definition.
What is it?
The parse.icon() method will allow the user to input an icon's name (or alias) as a string, an object, or an array when calling an icon. See our Vue docs for an example.
The parse.icon() method also normalizes our styles and icon names. For example, you can reference our solid icons with with a prefix of 'solid', 'fa-solid', 'fas', or 'fa'.
Additionally, you can reference our icons with just the icon name, which will default to solid style.
How to Use
Referencing the icon as a string:
import{ parse }from'@fortawesome/fontawesome-svg-core'// the icon's style will default to Solid, it's family will default to Classic
parse.icon('dog')// returns an object, with the default `fas` prefix// {prefix: 'fas', iconName: 'dog'}
Referencing the icon as an object with a short prefix name:
import{ parse }from'@fortawesome/fontawesome-svg-core'// No additional parsing was needed for this since it started with the prefix and icon name
parse.icon({prefix:'fas',iconName:'dog'})// {prefix: 'fas', iconName: 'dog'}// Same deal, no additional parsing is required for the Sharp family either
parse.icon({prefix:'fass',iconName:'cat'})// {prefix: 'fass', iconName: 'cat'}
Referencing the icon as an object with a long prefix name:
import{ parse }from'@fortawesome/fontawesome-svg-core'// a classic solid dog icon
parse.icon({prefix:'fa-solid',iconName:'dog'})// { prefix: 'fas', iconName: 'dog' }
Style name prefixed with fa- for prefix is no longer recommended
Why? Because you can't select the Sharp family.
Referencing the icon as an array with non-prefix:
import{ parse }from'@fortawesome/fontawesome-svg-core'// This only lets you select the Classic family:
parse.icon(['solid','dog'])
Using the style name, like solid is no bueno in array syntax
Why? Because you can't select the Sharp family.
Default Style
When calling the icons, if a style (solid, thin, duotone, etc.) is not specified or there is not a styleDefault set, the icon's class and style will default to solid.
Prefixes and Style Classes
Like the number of our icons, our styles have grown too! We now have icons in six styles. The chart below outlines all of our styles along with how you can use them with Font Awesome Icons:
Convenience method to convert an abstract representation of a Font Awesome object into its corresponding HTML markup.
The icon(), text(), layer(), and counter() functions each return a Font Awesome object that has properties abstract and html. (See also the documentation for icon() more details about the shape of such objects.)
toHtml() can be used to transform any abstract element into HTML.