fn-ui-avatars vs Raw API

Type a name to see the chaotic random colors of the raw API vs our deterministic ecosystem.

Native API (UI-Avatars)

Native API Avatar

❌ Using background=random makes colors change unpredictably on every keystroke/render for the same user.

❌ Causes inconsistent avatars for the same user across different devices or sessions.

<img src="https://ui-avatars.com/api/?name=..." />
fn-ui-avatars

The Ecosystem

John Doe

✅ Deterministic colors (John Doe always gets the exact same color).

✅ Smart contrast (Text adapts to the background).

✅ Framework agnostic core + React wrapper.

getAvatarUrl('John Doe');
Real World Context using fn-ui-avatars

Context 1: User Table

John Doe
John Doeuser@example.com

Context 2: Chat Bubble

John Doe

John Doe

Notice how my color matches the table perfectly?

Documentation

1. Choose your package

fn-ui-avatars

The core math engine. Zero dependencies. Use it in Vanilla JS, Vue, Svelte, Node, or via CDN.

npm install fn-ui-avatars

fn-ui-avatars-react

The official React wrapper. Ready-to-use component with seamless Tailwind CSS support.

npm install fn-ui-avatars-react

2. Usage

Vanilla JS (Core Package)

import { getAvatarUrl } from 'fn-ui-avatars'; const url = getAvatarUrl('Maria Silva'); document.getElementById('avatar').src = url;

React / Next.js Component

import { Avatar } from 'fn-ui-avatars-react'; <Avatar name="John Doe" /> <Avatar name="Light Name" />
John DoeLight Name

Custom Curated Palette

import { Avatar } from 'fn-ui-avatars-react'; <Avatar name="Alice" palette={['#F87171', '#FCD34D', '#10B981', '#4A7BCC']} /> <Avatar name="Bob" palette={['#F87171', '#FCD34D', '#10B981', '#4A7BCC']} />
AliceBob

3. API & Props Reference

Core API (Vanilla)

  • getAvatarUrl(name, options?)Returns the UI-Avatars URL string.
  • loadAvatars(selector?, options?)Scans the DOM and injects src attributes automatically.

React Wrapper

  • <Avatar name="John" {...options} />Renders a standard HTML <img> tag.
  • * Accepts all native image attributes like className, onClick, etc.

Configuration Options

These properties can be passed as an options object to the Core API, or directly as props to the React Component.

Prop / OptionTypeDefaultDescription
namestringRequiredThe name used to generate initials and deterministic background color.
sizenumber192Avatar image size in pixels.
fontSizenumber0.33Font size ratio (0.1 – 1).
lengthnumber2Number of initials to display.
roundedbooleantrueRenders a circular avatar if true, square if false.
colorstring'fff'Custom text color (hex with or without #). Overrides the default Smart Contrast.
palettestring[][]Array of custom hex colors to be used as the background. Picked deterministically.
format'svg' | 'png''svg'The image format returned by the API.
baseUrlstring'https://ui-avatars.com/api/'Custom API base URL if you are hosting your own instance.