Filter avatar variants with tags
Avatar styles can describe their variants with tags, short labels like hairLength:long or facialHair. Tags never change the artwork. They let you narrow the pool of variants an avatar is drawn from, the same way in every style that carries them.
Most of DiceBear's character styles carry tags for mood, hair length, headwear, facial hair, eyewear, and accessory. How DiceBear tags variants explains each of them.
Filter with the tags option
tags is a core option, so it works everywhere the avatar is generated. Pass the tags you want to keep:
https://api.dicebear.com/11.x/adventurer/svg?seed=John&tags=hairLength:long,mood:positiveimport { Style, Avatar } from '@dicebear/core';
import adventurer from '@dicebear/styles/adventurer.json' with { type: 'json' };
const style = new Style(adventurer);
const avatar = new Avatar(style, {
seed: 'John',
tags: ['hairLength:long', 'mood:positive'],
});use Composer\InstalledVersions;
use DiceBear\Avatar;
use DiceBear\Style;
$basePath = InstalledVersions::getInstallPath('dicebear/styles');
$style = Style::fromJson(file_get_contents($basePath . '/src/adventurer.json'));
$avatar = new Avatar($style, [
'seed' => 'John',
'tags' => ['hairLength:long', 'mood:positive'],
]);from importlib.resources import files
from dicebear import Avatar, Style
style = Style.from_json(
files("dicebear_styles").joinpath("adventurer.json").read_text("utf-8")
)
avatar = Avatar(style, {
"seed": "John",
"tags": ["hairLength:long", "mood:positive"],
})// cargo add dicebear-styles --features adventurer
use dicebear_core::{Avatar, Style};
use serde_json::json;
let style = Style::from_str(dicebear_styles::ADVENTURER)?;
let avatar = Avatar::new(&style, json!({
"seed": "John",
"tags": ["hairLength:long", "mood:positive"],
}))?;import (
dicebear "github.com/dicebear/dicebear-go/v11"
"github.com/dicebear/styles/v11"
)
style, _ := dicebear.NewStyle([]byte(styles.Adventurer))
avatar, _ := dicebear.NewAvatar(style, map[string]any{
"seed": "John",
"tags": []string{"hairLength:long", "mood:positive"},
})import 'package:dicebear_core/dicebear_core.dart';
import 'package:dicebear_styles/adventurer.dart';
final style = Style.parse(adventurer);
final avatar = Avatar(style, {
'seed': 'John',
'tags': ['hairLength:long', 'mood:positive'],
});using System.Text.Json.Nodes;
using DiceBear;
var style = Style.Parse(Styles.Adventurer);
var avatar = new Avatar(style, new JsonObject
{
["seed"] = "John",
["tags"] = new JsonArray("hairLength:long", "mood:positive"),
});In the HTTP API the tags are one comma-separated query parameter.
How the filter works
A tag token is category or category:value, optionally prefixed with !. Each token narrows a component's pool of variants:
| Token | Effect |
|---|---|
category:value | Keeps variants that carry this tag, plus variants with no tag in the category. Several values of one category act as "or". |
category | Requires the category: drops variants that carry no tag in it. |
!category:value | Drops every variant that carries exactly this tag. |
!category | Drops every variant that carries any tag in the category. |
A few rules tie the tokens together:
- A category only touches the components that use it, so you change one trait and the rest of the avatar stays varied.
- Different categories act as "and", and a disallow (
!) always wins over an allow. - A per-component variant option is more specific and takes precedence. When you pin a component's variant directly, the
tagsfilter is ignored for that component and applies only to the others. - Only an unknown category is ignored. An unknown value is not. Because no variant matches it, every variant tagged in that category drops out. A typo in
hairLenght:longchanges nothing, while a typo inhairLength:lngdrops every hair variant tagged with a length.
Tip
If a filter leaves a component with no matching variants, that component is not drawn. Loosen the filter or check the tags the style actually provides on its style page. Passing tags to a style that carries no tags does nothing.
Custom styles
A custom style can reuse the categories of the DiceBear styles, add its own values, or define entirely different ones. Reusing them keeps it compatible with the filter examples in these docs. The only rule is the grammar: a tag is category or category:value, and each segment is camelCase, for example mouthExpression:smug or species:robot.