Skip to content


This function is part of Iconify Utils package.

Function iconToHTML() generates SVG from a list of attributes for <svg> element and icon content.

It can be used with results of iconToSVG(), parseSVGContent() or buildParsedSVG().


Function has the following parameters:

  • body, string. Icon content, without <svg> tag.
  • attributes, Record<string,string>. Attributes to add, such as viewBox.

Function returns string.


Function adds the following attributes automatically, do not add them in attributes parameter:

  • "xmlns": always added.
  • "xmlns:xlink": added if body contains "xlink:". Modern icons should not contain "xlink:" attributes.

Attribute values are not modified. Make sure they are escaped before calling function.


tsimport { icons } from '@iconify-json/codicon';
import { getIconData, iconToSVG, iconToHTML, replaceIDs } from '@iconify/utils';

const iconName = 'debug-console';

// Get content for icon
const iconData = getIconData(icons, iconName);
if (!iconData) {
   throw new Error(`Icon "${iconName}" is missing`);

// Use it to render icon
const renderData = iconToSVG(iconData, {
   height: 'auto',

// Generate SVG string
const svg = iconToHTML(replaceIDs(renderData.body), renderData.attributes);

// Log SVG

Released under the Apache 2.0 License.