Cat avatars for your site
Give every user a cat. Use one image link, add a small script, or let people build their own cat with the picker and save it to their account.
Getting started
Pick the way that fits your site. All three draw the same cats.
Every way starts from the same rule: the same text always makes the same cat. Give it a user id and that user gets their own cat, with nothing to store. If you want people to choose their cat, the picker gives you a short cat code to save instead.
Image link
The quickest way. Put the link in an image tag and the cat is drawn for you.
<img src="https://catvatar.mocat.app/api/user-42.svg?size=96" width="96" height="96" alt="">Swap user-42 for anything: a user id, a username, a hash. Add settings after the ? to change the size, the shape, the colors or any part.
<img src="https://catvatar.mocat.app/api/Sam.svg?code=v1-012803203330001100&size=96" alt="Sam">Settings in the link
| Setting | Values |
|---|---|
code | A cat code from the picker, like v1-012803203330001100. Draws that exact cat; the name is then only the label |
size | 8 to 2048 pixels (80 if left out) |
shape | circle, squircle, square |
colors | A palette name (momo, catnip, sunset, sorbet, matcha, ocean, dusk, candy, biscuit) or five hex colors without #, separated by commas |
bg, accent | Which palette color (1 to 5) is the background and which the accessory. Leave out to let the name choose |
background | false for a see-through background |
coat | ginger, black, white, gray, cream, brown (Chocolate), blue |
fur | short, medium, long |
pattern | none (Solid), tabby, tuxedo, patch (Tortoiseshell), calico, points, split |
head | round, wide, chubby, heart |
ears | pointy, round, tiny, folded, lynx, bat |
eyes | round, big, slit, happy, sleepy, wink, dilated, constricted, mismatched |
mouth | w (Classic), smile, blep, open (Meow), fang, grin, grumpy, calm |
accessory | none, bow, flower, glasses, eyepatch (Eye patch), crown, party (Party hat) |
eyeColor, eyeColor2 | green, gold, blue, amber, copper, mint |
coat2 | Second coat for tortoiseshell and split: ginger, black, white, gray, cream, brown, blue |
point | For the points pattern: the face and ear color, ginger, black, white, gray, cream, brown, blue. Leave out for a darker shade of the coat |
sub | Which variation of the pattern, counting from 0 (solid: 0 plain, 1 star; tabby: 0 mackerel, 1 classic, 2 spotted; tuxedo: 0 blaze, 1 mask, 2 moustache, 3 white chin, 4 lopsided, 5 thin blaze, 6 bib, 7 forehead streak, 8 nose streak; tortoiseshell: 0 eye spot, 1 ear patch, 2 cap; calico: 0 classic, 1 tortie, 2 dilute, 3 phoenix 1, 4 phoenix 2; points: 0 mask, 1 lynx, 2 snowshoe; split: 0 half, 1 diagonal) |
whiskers, muzzle, blush | true or false |
Every image is drawn when it is asked for. Only the visitor's own browser keeps a copy, for a day.
Script tag
Add one script and draw cats right in the browser. Nothing is sent anywhere.
<script src="https://cdn.jsdelivr.net/npm/catvatar@1/dist/catvatar.min.js"></script>
<!-- a tag that draws a cat -->
<cat-avatar name="user-42" size="48"></cat-avatar>
<cat-avatar code="v1-012803203330001100" size="48" shape="squircle"></cat-avatar>The <cat-avatar> tag takes name or code, plus size (pixels or any CSS length), shape, colors and label (the text screen readers hear). It redraws when you change an attribute.
// an <img> with a user's cat
document.querySelector("#avatar").src = Catvatar.dataUri(user.id);
// or the SVG markup itself
el.innerHTML = Catvatar.svg(user.catCode || user.id, { size: 64 });The script is also served by this site at https://catvatar.mocat.app/catvatar.min.js, if you would rather not use jsDelivr.
npm and React
The same package for bundlers, with TypeScript types.
npm install catvatarimport { svg } from "catvatar";
export function Avatar({ user, size = 40 }) {
const markup = svg(user.catCode || user.id, { size });
return <span role="img" aria-label={user.name} dangerouslySetInnerHTML={{ __html: markup }} />;
}The markup comes from Catvatar itself, never from what users type, so it is safe to put in the page. Importing the package also defines <cat-avatar>, so you can use the tag in any framework.
Avatar picker
Let people make their own cat instead of uploading a photo. It opens on top of your page and gives you the cat to save.
No cat saved yet, so the name draws one. That works as a default avatar.
<script src="https://cdn.jsdelivr.net/npm/catvatar@1/dist/catvatar.min.js"></script>
<button id="pick">Choose your cat</button>
<script>
document.querySelector("#pick").onclick = async () => {
const cat = await Catvatar.pick({ code: user.catCode });
if (!cat) return; // they closed it
// save it with the account, like any other profile field
await fetch("/api/profile", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ catCode: cat.code }),
});
};
</script>Options
| Option | What it does |
|---|---|
code | Open a cat saved earlier, so people can change it |
name | Start from the cat this text makes (a random cat if left out) |
title | The heading. "Choose your cat" if left out |
saveLabel | The save button. "Use this cat" if left out |
theme | "light", "dark" or "auto" (follows the visitor's setting) |
shapes | Which shapes people can pick, like ["circle"] if your site always shows round avatars |
What you get back
pick() gives null if the person closes it, or:
| Field | What it is |
|---|---|
code | The cat code. Save this: 21 characters, or 52 with custom colors |
svg | The picture as SVG markup, if you would rather store the image |
dataUri | The picture as a data: URL, ready for <img src> |
png(size) | Makes a PNG file (a Blob) to upload to your own storage. 256 pixels if left out |
Match your site
The picker keeps its own styles, so your CSS cannot break it. Change its colors with these variables:
catvatar-picker {
--cv-accent: #7a5af8; /* buttons and selected parts */
--cv-on-accent: #ffffff; /* text on the accent */
--cv-radius: 14px;
--cv-font: inherit;
--cv-bg: #ffffff; --cv-text: #1d1b22; --cv-muted: #6b6675; --cv-line: #e3e0e8;
/* dark theme: the same names ending in -dark, like --cv-bg-dark */
}Cat codes
One short line of text that holds a whole cat. Store it like any other text field.
v1-012803203330001100 is Momo: a black tuxedo with a nose streak, round eyes and an open mouth, on the Momo palette.
- A code holds every part, the palette and the shape. It does not depend on any name, so people can rename themselves and keep their cat.
- Codes start with a version (
v1-). A saved code always opens the same cat. - Check a code before you save it with
Catvatar.isCode(text). It is safe to show in pages and links: only letters, numbers and dashes. - Show it with
<cat-avatar code="…">,Catvatar.svg(code)or the image link with?code=.
On your server
The package has no dependencies and runs anywhere JavaScript does: Node, Bun, Deno and Cloudflare Workers.
import { svg, isCode } from "catvatar";
// check what the browser sent before saving it
if (!isCode(req.body.catCode)) return res.status(400).send("Not a cat code");
// draw an avatar for an email, a PDF or an image API of your own
const markup = svg(user.catCode || user.id, { size: 128 });All functions
| Function | What it does |
|---|---|
svg(textOrCode, options) | The cat as SVG markup. Options: size, shape, colors, background, title |
dataUri(textOrCode, options) | The same as a data: URL for <img src> |
png(textOrCode, size) | A PNG file (Blob). Browser only |
pick(options) | Opens the avatar picker. Browser only |
codeFor(text) | The cat code of the cat a text makes, so the picker can open it for editing |
isCode(text) | True when the text is a valid cat code |
decode(code) | Reads a code into its parts (traits, shape, colors), or null |
defineElement(tag) | Registers the avatar tag under another name, if cat-avatar is taken |
Privacy and versions
- The script never sends anything. Cats are drawn on the visitor's device. There is no tracking and no account.
- Do not put emails in image links. Links show up in logs and browser history. Use a user id, or a hash of the email.
- Cat codes do not change. A
v1-code opens the same cat for as long as this exists. - Pin the major version.
catvatar@1on jsDelivr gets fixes but never a change that redraws your users' cats.