Photo With Initials Fallback
Photo when it loads, initials when it doesn't. The avatar every app needs first.
Create a reusable <Avatar /> React component with Tailwind CSS. Pattern: basic avatar with image and initials fallback. Layout: circular avatar rendering an <img> when src loads; on error or missing src, render a generated initials fallback with a deterministic background color derived from the name string. API: props for src, name (required, used for alt text and initials), size ("xs" | "sm" | "md" | "lg" | "xl"), and className passthrough. Include: required alt text from name, loading="lazy", onError fallback swap via local state, focus-visible ring when rendered inside a link or button, light and dark support via Tailwind dark: classes. Constraints: React + Tailwind only, no external UI or image dependencies, no layout shift while the image loads (reserve the box with fixed width/height).






