Skip to content

SVG framework function: renderHTML

This tutorial is part of Iconify SVG Framework functions tutorial.

Function renderHTML() generates HTML code for icon.

Usage

Function has the following parameters:

  • name, string. Icon name.
  • customisations. Optional customizations object.

Function returns string, null if icon is not available.

Examples

jsif (Iconify.iconExists('mdi:home')) {
   node.innerHTML = Iconify.renderHTML('mdi:home');
}

Another example:

jsconst node = document.createElement('div');
node.innerHTML = Iconify.renderHTML('bi:stopwatch', {
   rotate: 1,
   height: 'auto',
});

Customizations

Second parameter is optional icon customizations. Do not confuse it with placeholder data- attributes.

Available customizations:

IconifyIconCustomisations type is an object with the following optional properties, split into several categories.

Vertical alignment:

  • inline, boolean. If enabled, adds vertical-align: -0.125em to style, rendering icon below baseline. The default value is false.

Icon dimensions:

  • width, string|number|null. Icon width. The default value is null.
  • height, string|number|null. Icon height. The default value is null.

There are several keywords that can be used for width and height:

  • "auto" sets dimension to original icon's dimensions found in viewBox.
  • "unset" and "none" remove dimensions from SVG.

If neither of dimensions is set, height defaults to "1em".

It is enough to set one dimension, such as height. Another dimension will be calculated using icon's width/height ratio. In the case of keywords, another dimension will be set to the same keyword.

Transformations:

  • hFlip, boolean. Flip icon horizontally. The default value is false.
  • vFlip, boolean. Flip icon vertically. The default value is false.
  • rotate, number. Rotation in 90 degrees increments. The default value is 0.

For more details about dimensions and alignment see icon dimensions documentation.

For more details about transformations see icon transformations documentation.

Rendering SVG

This function creates <string>. If you want to create <svg> element, use renderSVG() instead.

Released under the Apache 2.0 License.