Try it and see the difference.
❌ Using background=random makes colors change unpredictably on every 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=..." />✅ 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');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" />getAvatarUrl(name, options?)Returns the UI-Avatars URL string.loadAvatars(selector?, options?)Scans the DOM and injects src attributes automatically.<Avatar name="John" {...options} />Renders a standard HTML <img> tag.className, onClick, etc.These properties can be passed as an options object to the Core API, or directly as props to the React Component.
| Prop / Option | Type | Default | Description |
|---|---|---|---|
| name | string | Required | The name used to generate initials and deterministic background color. |
| size | number | 192 | Avatar image size in pixels. |
| fontSize | number | 0.33 | Font size ratio (0.1 – 1). |
| length | number | 2 | Number of initials to display. |
| rounded | boolean | true | Renders a circular avatar if true, square if false. |
| color | string | 'fff' | Text color hex (without #). Automatically outputs 'fff' or '000' for best contrast. |
| format | 'svg' | 'png' | 'svg' | The image format returned by the API. |
| baseUrl | string | 'https://ui-avatars.com/api/' | Custom API base URL if you are hosting your own instance. |