New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-name-initials-avatar

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-name-initials-avatar

Creating Stylish Initial-Based Avatars in React

latest
Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
1K
5.13%
Maintainers
1
Weekly downloads
 
Created
Source

react-name-initials-avatar

Npm Package Url - https://www.npmjs.com/package/react-name-initials-avatar

The react-name-initials-avatar is a lightweight and customizable React component that generates avatars based on user names or initials. This component is ideal for user profile displays, comment sections, or any application where you want to visually represent users with avatars.

React Name Initals Avatar

Features

  • Customizable - You can easily customize the appearance of the avatars by adjusting properties like size, background colors, text colors, and more.
  • Easy Integration - Integrating the React Name Initials Avatar into your project is simple. Just import the component and pass the necessary props.
  • Auto Color - Automatically generate consistent colors based on user names.
  • Flexible Initials - Control how many initials to display (1, 2, or 3).
  • Shape Options - Easily switch between circle and square shapes.

Installation

yarn add react-name-initials-avatar

OR

npm install react-name-initials-avatar

Usage

To use the component, import it into your React application:

import {NameInitialsAvatar} from 'react-name-initials-avatar';

function UserProfile(props) {
  const { username } = props;

  return (
    <div className="user-profile">
      <NameInitialsAvatar
        name={username}
      />
      <h2>{username}</h2>
    </div>
  );
}

export default UserProfile;

In the above example, the NameInitialsAvatar component generates an avatar based on the user's name initials. You can customize the avatar's size, background color, border radius, font weight and text color according to your design.

Props

KeyDefaultType
name (required)undefinedstring
bgColorwhitestring
textColorblackstring
size40pxstring | number
borderRadius50%string
textWeightboldstring | number
textSize16pxstring | number
borderColorblackstring
borderStylesolidstring
borderWidth2pxstring | number
shapeundefined"circle" | "square"
autoColorfalseboolean
initialsLengthundefined1 | 2 | 3

Props Description

  • name - name of user
  • bgColor - set background color
  • textColor - set text color
  • size - set container size. Accepts "40px", "40", or 40 (auto-converts to px)
  • borderRadius - set border radius of container
  • textWeight - set font weight of text. Accepted values - normal, bold, bolder, lighter, number, initial, inherit, 100 to 900
  • textSize - set font size of text. Accepts "16px", "16", or 16 (auto-converts to px)
  • borderColor - set border color of container
  • borderStyle - set border style of container. Accepted values - none, hidden, dotted, dashed, solid, double, groove, ridge, inset, outset, initial, inherit
  • borderWidth - set border width of container. Accepts "2px", "2", or 2 (auto-converts to px)
  • shape - set avatar shape. Accepted values - "circle", "square". Note: borderRadius takes precedence over shape if both are provided
  • autoColor - when true, automatically generates a consistent background color based on the name. Note: bgColor takes precedence over autoColor if both are provided
  • initialsLength - control how many initials to display (1, 2, or 3). For "John Michael Doe": 1 shows "J", 2 shows "JD", 3 shows "JMD"

Examples

Basic Usage

<NameInitialsAvatar name="John Doe" />

Auto Color

Each name generates a unique, consistent color:

<NameInitialsAvatar name="John Doe" autoColor textColor="white" />
<NameInitialsAvatar name="Jane Smith" autoColor textColor="white" />

Shape

<NameInitialsAvatar name="Circle" shape="circle" />
<NameInitialsAvatar name="Square" shape="square" />

Initials Length

<NameInitialsAvatar name="John Michael Doe" initialsLength={1} /> {/* J */}
<NameInitialsAvatar name="John Michael Doe" initialsLength={2} /> {/* JD */}
<NameInitialsAvatar name="John Michael Doe" initialsLength={3} /> {/* JMD */}

Custom Styling

<NameInitialsAvatar
  name="John Doe"
  bgColor="#3498db"
  textColor="white"
  size={60}
  borderRadius="12px"
  borderColor="#2980b9"
  borderWidth={3}
/>

Precedence Rules

  • Background Color: bgColor > autoColor > default ("white")
  • Border Radius: borderRadius > shape > default ("50%")

Keywords

component

FAQs

Package last updated on 06 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts