Renders an indenticon as a SVG string. The response can either be used in the DOM or saved as a file with the *.svg extension. This method does not have any dependencies to the DOM and can be used to generate icons server-side e.g. by using Node.js.

jdenticon.toSvg(hash|value, size[, padding])
Browser: Yes Node.js: Yes


In the following example an identicon is rendered as an svg string that is inserted into the page.

Usage browser

<div id="identiconPlaceholder">

<script src="https://cdn.jsdelivr.net/npm/jdenticon@2.1.1"></script>
    var placeholder = document.getElementById("identiconPlaceholder");
    placeholder.innerHTML = jdenticon.toSvg("icon value", 200);

Below is an example how an SVG file can be generated using Node.js.

Usage Node.js

var jdenticon = require("jdenticon"),
    fs = require("fs"),
    svg = jdenticon.toSvg("icon value", 200);

fs.writeFileSync("./testicon.svg", svg);


hash|value is considered a hash string if the string is hexadecimal and contains at least 11 characters. It is otherwise considered a value that will be hashed using SHA1.

size defines the width and height, icons are always square, of the icon in pixels, including its padding.

padding specifies the padding surrounding the icon in percents in the range 0.0 to 0.5. Default is 0.08.