Definition schema reference
Every DiceBear avatar style is a JSON file that follows the DiceBear Definition Schema. It describes everything needed to generate an avatar: the canvas size, the SVG elements, the components that can be randomized, the color palettes, and optional animations. The definition is purely declarative, and the rendering logic lives in the DiceBear Core. This page documents schema version 3.0.0, the version DiceBear 11 uses. For a guided example, see Create an avatar style from scratch.
Top-level structure
{
"$schema": "https://...",
"$id": "https://...",
"$comment": "Optional comment",
"meta": { ... },
"canvas": { ... },
"components": { ... },
"colors": { ... },
"attributes": { ... }
}| Property | Required | Description |
|---|---|---|
$schema | No | URL to the definition schema for editor validation |
$id | No | Canonical identifier for this definition (typically the URL it is hosted at, max 256 chars) |
$comment | No | Free-text comment, e.g. "Generated by Figma" (max 4096 chars) |
meta | No | License, creator, and source metadata |
canvas | Yes | Canvas dimensions and root element tree |
components | No | Named, randomizable SVG components (up to 512 entries) |
colors | No | Named color palettes for dynamic coloring (up to 512 entries) |
attributes | No | Global SVG attributes for the root <svg> element |
Names of components, variants, colors, and animations are camelCase: a lowercase letter first, then letters and digits, up to 64 characters.
meta
Metadata about the style, used in license comments, the CLI banner, and the documentation.
{
"meta": {
"license": {
"name": "CC0 1.0",
"url": "https://creativecommons.org/publicdomain/zero/1.0/",
"text": "Full license text..."
},
"creator": {
"name": "DiceBear",
"url": "https://www.dicebear.com"
},
"source": {
"name": "Initials",
"url": "https://github.com/dicebear/dicebear"
}
}
}canvas
Defines the SVG viewport and the root element tree. The width and height determine the viewBox of the generated SVG.
{
"canvas": {
"width": 100,
"height": 100,
"elements": [
{ "type": "component", "name": "background" },
{ "type": "component", "name": "face" }
]
}
}| Property | Type | Required | Description |
|---|---|---|---|
width | number | Yes | Canvas width in pixels (1 to 1,000,000) |
height | number | Yes | Canvas height in pixels (1 to 1,000,000) |
elements | array | Yes | Root element tree (up to 1024 top-level entries) |
Elements
Elements are the building blocks of the SVG. Three types are supported:
element: SVG tag
Renders an SVG element like <circle>, <path>, <g>, etc.
{
"type": "element",
"name": "circle",
"attributes": {
"cx": "50",
"cy": "50",
"r": "40",
"fill": { "type": "color", "name": "skin" }
},
"children": []
}Only whitelisted SVG elements are allowed (e.g. circle, path, g, rect, text, defs, filter, linearGradient, radialGradient, etc.). Elements like script, foreignObject, and a are blocked for security.
A node may have at most 1024 children. The element with name: "defs" has special semantics (see Reusable <defs> entries below). An element may also carry an animations array (see Animations).
text: text content
Renders raw text inside an SVG element. Supports variable references.
{
"type": "text",
"value": "Hello"
}Or with a variable:
{
"type": "text",
"value": { "type": "variable", "name": "initials" }
}Only initial and initials are accepted in a text value. Other variables (fontFamily, fontWeight) are only valid in their dedicated attributes (see Variable references).
component: component reference
References a named component defined in the components section. The DiceBear Core will select a variant based on the seed and options.
{
"type": "component",
"name": "eyes"
}A component reference can carry its own attributes map. They are written verbatim onto the emitted <use> element, which is how you place an instance of a component on the canvas:
{
"type": "component",
"name": "eyes",
"attributes": {
"transform": "translate(10 20)"
}
}A user-supplied transform is prepended to the per-component rotate/translate/scale picked by the renderer, so it acts as the outer (placement) transform.
A component reference may carry animations as well. They move the placed instance, so two references to the same component can animate differently.
The <style> element
<style> is supported but is a special case. Its CSS body must be supplied as one or more text children, not as a single string and not via children holding generic elements:
{
"type": "element",
"name": "style",
"children": [
{
"type": "text",
"value": ".dark { fill: #000; }"
}
]
}A <style> element may hold at most 64 text children and cannot carry animations. The CSS body is sanitized more strictly than ordinary attribute values:
- Known-dangerous
@-rules (@import,@font-face,@document,@charset) are rejected. Other at-rules (@media,@keyframes,@supports,@layer, …) are permitted, but their contents are still passed through the common filter described below.
The following are rejected in every CSS body and every attribute value (the shared filteredString injection filter):
- External
url(...)references (localurl(#id)is fine) expression(...),behavior:,-moz-bindingjavascript:andvbscript:URI schemes- Backslash escape sequences
The filter also catches these tokens with whitespace before the colon or the parenthesis, and a remote URL with whitespace after url(. Whitespace here means space, tab, line feed, form feed, and carriage return, the characters a URL or CSS parser skips at these spots.
This is a defense-in-depth filter, not a CSS validator: substring matches reject otherwise-harmless strings that happen to contain a blocked token (e.g. the literal word javascript: in plain text).
Reusable <defs> entries
<defs> is whitelisted as an ordinary element, but the renderer treats it specially: every child of an element named defs, anywhere in the tree, is hoisted into the document-wide <defs> block alongside generated gradients, clip paths, and component bodies. This keeps the rendered SVG to a single <defs> element while letting style authors ship reusable fragments (filters, gradients, masks, …) and reference them from elsewhere in the tree.
Nothing below defs may carry animations. Animate the <use> element that references the def instead (see Where animations are allowed).
Animations
An element or a component reference may carry an animations array with one to eight timelines. Each timeline moves the node through keyframes, one track per animated property. Renderers turn the timelines into CSS inside the SVG, but only when the user switches them on with the animation option or a per-name switch (see Core options). Otherwise the output stays static, and so does every raster conversion.
{
"type": "component",
"name": "eyes",
"animations": [
{
"name": "blink",
"duration": 4,
"tracks": {
"scaleY": {
"keyframes": [
{ "at": 90, "value": 1, "easing": "easeIn" },
{ "at": 95, "value": 0.1, "easing": "easeOut" },
{ "at": 100, "value": 1 }
]
}
}
},
{
"duration": 3,
"direction": "alternate",
"easing": "easeInOut",
"tracks": {
"translateY": {
"keyframes": [
{ "at": 0, "value": 0 },
{ "at": 100, "value": -2 }
]
}
}
}
]
}The first timeline is named blink. The eyes stay open for 90 % of each four-second cycle, then close and open again within the last 10 %. The second timeline has no name and lets the eyes drift up and back down.
Timelines
| Property | Type | Description |
|---|---|---|
name | string | Optional. Groups the timeline under the per-name options, see Animation names |
duration | number | Required. Length of one iteration in seconds, above 0 and up to 3600 |
delay | number | Optional. Start delay in seconds, -3600 to 3600 (default 0). A negative value starts the timeline mid-cycle |
iterations | number or "infinite" | Optional. How often the timeline runs, above 0 and up to 10,000 (default "infinite") |
direction | string | Optional. normal, reverse, alternate, or alternateReverse, as in CSS animation-direction (default normal) |
fill | string | Optional. forwards keeps the last keyframe's value after a finite run, none returns to the resting state (default none) |
easing | easing | Optional. Easing for every segment whose keyframe sets none (default linear), see Easing |
origin | object | Optional. { x, y } pivot for rotate, scaleX, and scaleY in percent of the node's bounding box, -1000 to 1000 (default { "x": 50, "y": 50 }) |
tracks | object | Required. One or more of the tracks below |
The renderer applies these defaults. The schema only checks the ranges.
Tracks
| Track | Keyframe value |
|---|---|
translateX | Horizontal offset from the resting position in user units. Positive values move right |
translateY | Vertical offset from the resting position in user units. Positive values move down |
rotate | Degrees around origin, added to the resting transform. Positive values turn clockwise, 360 is one full turn |
scaleX | Horizontal scale factor around origin. 1 is the resting size |
scaleY | Vertical scale factor around origin. 1 is the resting size |
opacity | Opacity of the node |
Tracks compose in a fixed order: translation outside rotation, rotation outside scale, and opacity innermost. The order of the keys in tracks makes no difference.
When the node has an opacity attribute, an opacity track replaces that value while it plays instead of multiplying with it. A part with opacity="0" therefore stays hidden in static output and appears only through its animation.
Keyframes
Each track holds 1 to 64 keyframes:
| Property | Type | Description |
|---|---|---|
at | number | Required. Position on the timeline in percent of duration, 0 to 100 |
value | number | Required. Value of the track at this position, -36000 to 36000 |
easing | easing | Optional. Shapes the segment from this keyframe to the next one. Falls back to the timeline's easing |
List the keyframes in strictly ascending at order. JSON Schema cannot express that rule, so the renderer checks it when it loads the definition and rejects unordered or duplicate positions. For an instant jump, give the keyframe before it the hold easing instead of placing two keyframes at the same position.
When the first keyframe of a track sits after 0 % or the last one before 100 %, the renderer pads the ends with a copy of the nearest keyframe. The value then holds outside the keyframed span. The blink example above relies on this to keep the eyes open until 90 %.
Easing
An easing is a keyword or a cubic Bézier curve:
linear,ease,easeIn,easeOut, andeaseInOutmatch the CSS timing functionslinear,ease,ease-in,ease-out, andease-in-out.holdkeeps the value until the next keyframe and then jumps (CSSstep-end).{ "x1": 0.3, "y1": 0, "x2": 0.2, "y2": 1.4 }is a CSScubic-bezier().x1andx2stay within 0 to 1.y1andy2may range from -4 to 4, which allows curves that overshoot.
Animation names
A name ties timelines to user options. For timelines named blink, blinkAnimation switches them on or off, blinkAnimationSpeed sets their speed, and blinkAnimationDelay their start offset. Each of these wins over the global animation, animationSpeed, and animationDelay option for that name. Several timelines may share one name, for example one per eye, and are then switched together. A timeline without a name follows the global options only. Core options lists the values these options take.
Where animations are allowed
The renderer plays a timeline by wrapping the node in a <g> element. Some places cannot take that wrapper, so the schema rejects animations there:
- Anywhere below
defsorclipPath. A<use>clones only the node it references, so an animation on a def never reaches the instance. A<g>is not valid clip path content either. Animate the<use>element instead. - On elements a group cannot wrap:
stop,tspan,textPath,mpath, and the filter primitives (feBlend,feGaussianBlur, and the otherfe*elements). - On the
<style>element.
Elements below mask may carry animations.
Animations in CSS
A <style> element with @keyframes rules remains valid. The renderer passes that CSS through as written: the animation option does not switch it, and the reduced-motion media query around declarative animations does not cover it.
components
Named, randomizable parts of the avatar. Each component defines a set of variants that the PRNG can choose from.
{
"components": {
"eyes": {
"width": 80,
"height": 40,
"probability": 100,
"rotate": { "min": -10, "max": 10 },
"scale": { "min": 0.9, "max": 1.1 },
"translate": {
"x": { "min": 0, "max": 0 },
"y": { "min": -5, "max": 5 }
},
"variants": {
"happy": {
"weight": 1,
"elements": [...]
},
"surprised": {
"weight": 1,
"elements": [...]
}
}
}
}
}| Property | Type | Description |
|---|---|---|
width | number | Required. Component canvas width in pixels (1 to 1,000,000) |
height | number | Required. Component canvas height in pixels (1 to 1,000,000) |
probability | number | Optional. Chance the component appears, 0 to 100 (default 100) |
rotate | object | Optional. Rotation range, see Ranges |
scale | object | Optional. Scale range around the component's center, see Ranges |
translate | object | Optional. { x?: Range, y?: Range } offsets as a percentage of the component's own width / height, see Ranges |
variants | object | Required. Named variant definitions (up to 512) |
A translate value of 100 shifts the component by its full width or height, 0 leaves it in place. The example above (y: { min: -5, max: 5 }) shifts the component vertically by up to 5 % of its height in either direction.
Ranges
rotate, scale, translate.x, and translate.y all use the same range object:
{ "min": -10, "max": 10, "step": 5 }| Property | Type | Description |
|---|---|---|
min | number | Required. Lower bound of the range |
max | number | Required. Upper bound of the range |
step | number | Optional. Positive value that quantizes the range to min + i × step |
For a fixed value, set min === max. With step, the PRNG samples from { min + i × step | 0 ≤ i ≤ ⌊(max − min) / step⌋ }, so when (max − min) is not a multiple of step, max itself is unreachable. Without step, the range is continuous.
The numeric domains differ per field: rotate and the inner step values are in degrees (-360 to 360, step ≤ 720), scale is 0 to 10 (step ≤ 10), and translate.x / translate.y are percentages from -1000 to 1000 (step ≤ 2000).
Component aliases
A component can be aliased to another component using extends. An alias has no dimensions or variants of its own: it inherits everything from the referenced component, but renders as an independent, separately-randomized instance. This is useful when you want the same visual component to appear twice (e.g. left and right earrings) and have each occurrence pick its own variant.
{
"components": {
"earring": {
"width": 20,
"height": 20,
"variants": {
"stud": { "elements": [...] },
"hoop": { "elements": [...] }
}
},
"earringLeft": { "extends": "earring" },
"earringRight": { "extends": "earring" }
}
}extends is the only property an alias may have, and it must point to a base component (not another alias) in the same components map. The schema cannot check that reference, so the renderer rejects an unknown target or an alias chain when it loads the definition. Aliases have no user options of their own and share ${sourceName}Variant and ${sourceName}Probability with their source, while each alias still picks its own variant within those constraints. See the implementation guide for details.
Variants
Each variant contains an element tree, an optional weight, and optional tags:
| Property | Type | Default | Description |
|---|---|---|---|
elements | array | — | Required. SVG element tree for this variant (up to 1024) |
weight | number | 1 | Selection weight for the PRNG (0 to 1,000,000) |
tags | string[] | — | Tags the tags option filters by (up to 32), see Variant tags |
Higher weights make a variant more likely to be selected. A weight of 0 keeps the variant out of the random pick. It is drawn only when every variant left in the pool has weight 0, for example after the tags option narrowed the pool to such variants. The PRNG then falls back to an unweighted pick among them. A user-set ${name}Variant option brings its own weights (1 for each named variant unless the option maps names to weights), so it can select a weight-0 variant directly.
Variant tags
Tags describe what a variant shows, so users can filter the variant pool with the tags option:
{
"variants": {
"shoulderLength": {
"tags": ["hairLength:long"],
"elements": [...]
},
"cropWithCap": {
"tags": ["hairLength:short", "headwear:cap"],
"elements": [...]
}
}
}A tag is a category or a category:value token, and each segment is camelCase. A variant may carry up to 32 tags, each at most once. Without the tags option the tags have no effect on the avatar.
A category:value tag also counts for its whole category, so !headwear drops the cropWithCap variant above. Set a bare category tag only when no value fits the variant.
The categories planned for DiceBear's own styles are listed in How DiceBear tags variants, and a custom style is free to add its own.
colors
Named color palettes. The PRNG picks a color from the palette based on the seed.
{
"colors": {
"skin": {
"values": ["#f5d6c3", "#d4a889", "#a67c5b", "#614335"]
},
"text": {
"values": ["#ffffff", "#000000"],
"contrastTo": "skin"
},
"hair": {
"values": ["#2c1b18", "#b58143", "#d6b370", "#724133"],
"notEqualTo": ["skin"]
}
}
}| Property | Type | Description |
|---|---|---|
values | string[] | Required. Hex colors in #RGB, #RGBA, #RRGGBB, or #RRGGBBAA form (1 to 128 entries). With *ColorOrder: 'fixed' and no user colors, the palette is used in this order |
contrastTo | string | Optional. Pick the color with highest contrast to this group's selection |
notEqualTo | string[] | Optional. Filter out colors already picked by these groups (up to 64 refs) |
A definition may declare up to 512 color groups.
Color constraints
contrastTo bypasses random selection. Instead, the candidate colors are sorted by WCAG 2.1 contrast ratio against the referenced color, and the highest-contrast color is picked. This is useful for ensuring text readability.
notEqualTo filters out colors that were already selected for the referenced color groups. This prevents adjacent parts from having the same color. Comparison is done on the RGB hex (alpha stripped). If the filter would leave the candidate list empty, the renderer falls back to the unfiltered list.
The schema does not detect cycles (a ⇄ b constraints). Renderers throw at render time when they run into one.
Color references in attributes
Color-bearing attributes (fill, stroke, stop-color, color, flood-color, lighting-color) accept either a literal CSS color string (named color, hex, rgb(), oklch(), color-mix(), a local paint server reference like url(#id), …) or a reference to a named palette:
{
"fill": { "type": "color", "name": "skin" }
}A palette reference is resolved at render time to the color the PRNG picked for the skin group. Literal strings are not validated as CSS (invalid syntax is the browser's problem), but the shared injection filter still applies (no javascript:, no external url(...), …).
Variable references
A handful of properties accept a { "type": "variable", "name": "…" } object in place of a literal string. Each variable is only valid in a specific spot. The schema rejects mismatched placements.
| Variable | Allowed in | Resolves to |
|---|---|---|
initial | text element value | First character of the initials derived from the seed |
initials | text element value | Full initials (1 to 2 characters) derived from the seed |
fontFamily | font-family attribute | Resolved fontFamily user option (defaults to system-ui) |
fontWeight | font-weight attribute | Resolved fontWeight user option (defaults to 400) |
{
"type": "text",
"value": { "type": "variable", "name": "initials" }
}{
"attributes": {
"font-family": { "type": "variable", "name": "fontFamily" },
"font-weight": { "type": "variable", "name": "fontWeight" }
}
}attributes
Global SVG presentation attributes applied to the root <svg> element.
{
"attributes": {
"fill": "none",
"shape-rendering": "auto"
}
}Only safe SVG presentation attributes are allowed. Event handlers (onclick, …) and namespaced attributes (xlink:href, …) are rejected. See the schema source for the complete whitelist.
Two attributes have notable extra rules:
hrefaccepts only local fragment refs (#id) and embedded raster images encoded asdata:image/{png|gif|jpeg|webp|avif};base64,…. Remote URLs (http(s)://…) and<script>/xlink:hrefpatterns are rejected.styleis sanitized as a CSS string: the stricter<style>-element ruleset applies (see The<style>element).
Schema package
The schemas live in @dicebear/schema and ship two files (both JSON Schema draft-07):
definition.json: validates style definitionsoptions.json: validates the user options passed toAvatar
Install via your package manager:
| Ecosystem | Install |
|---|---|
| npm | npm install @dicebear/schema |
| Composer | composer require dicebear/schema |
| PyPI | pip install dicebear-schema |
| Cargo | cargo add dicebear-schema |
| Go | go get github.com/dicebear/schema/v3 |
| pub.dev | dart pub add dicebear_schema |
| NuGet | dotnet add package DiceBear.Schema |
Or reference the schema directly from a CDN, handy for the $schema field of your style definition so editors like VS Code provide autocomplete and inline validation:
https://cdn.hopjs.net/npm/@dicebear/schema@3.0.0/dist/definition.min.json
https://cdn.hopjs.net/npm/@dicebear/schema@3.0.0/dist/options.min.json