npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

string-to-color-gradient

v1.0.13

Published

A lightweight npm library to convert any string into consistent hex colors and CSS gradients — perfect for avatars, tags, themes, blog cards, and visual identifiers. Turn names, emails, or any string into beautiful, deterministic color values that stay th

Downloads

560

Readme

🎨 string-to-color-gradient

Live Interactive Demo - Click Here

A lightweight npm library to convert any string into consistent hex colors and CSS gradients — perfect for avatars, tags, themes, blog cards, and visual identifiers.

Turn names, emails, or any string into beautiful, deterministic color values that stay the same every time.

✨ Features

  • 🔁 Deterministic output – same input always gives the same result
  • 💡 Color Brightness control – choose from light, normal, or dark styles
  • 🎨 Hex colors or full CSS gradients
  • 🔒 Hash-based uniqueness using MD5, SHA-1, or SHA-256
  • 📦 Tiny footprint – zero config, ready to use
  • Fast and dependency-light – built for performance

📦 Installation

npm install string-to-color-gradient

or with Yarn:

yarn add string-to-color-gradient

🚀 Quick Start

import {
  stringToColor,
  stringToGradient,
  stringToCssGradient,
} from 'string-to-color-gradient';

const color = stringToColor('hello world');
// => "#d87c3a"

const [start, end] = stringToGradient('hello world');
// => ["#d87c3a", "#4e92bf"]

const cssGradient = stringToCssGradient('hello world');
// => "linear-gradient(123deg, #d87c3a, #4e92bf)"

⚙️ Options

Customize the output using the optional GradientOptions object.

interface GradientOptions {
  brightness?: 'dark' | 'normal' | 'light'; // default: 'normal'
  angle?: 'auto' | number; // default: 'auto'
}

💡 Brightness

| Value | Description | Visual Style | | -------- | -------------------- | ---------------- | | light | Softer, pastel tones | 🌤️ Light & airy | | normal | Balanced default | ☁️ Neutral tones | | dark | Rich and saturated | 🌑 Deep contrast |

📐 Angle

  • 'auto' – angle is generated from the string hash (default)
  • number – specify a custom angle in degrees (e.g., 45, 120)

🧩 API Reference

stringToColor(str: string, brightness?: Brightness): string

🔹 Converts a string to a single hex color.

stringToColor('Hello World', 'light');
// => "#c4a2e1"

stringToGradient(str: string, options?: GradientOptions): [string, string]

🔹 Returns a tuple of two hex colors to create gradients.

stringToGradient('Hello World', { brightness: 'dark' });
// => ["#7a2b7c", "#2c8d4d"]

stringToCssGradient(str: string, options?: GradientOptions): string

🔹 Returns a complete CSS linear-gradient(...) string.

stringToCssGradient('Hello World', { angle: 45 });
// => "linear-gradient(45deg, #a1b2c3, #d4e5f6)"

🛠 Use Cases

Make your UI more vibrant, consistent, and automatic — no color picking required:

  • 👤 Avatar backgrounds – assign users a unique, consistent color
  • 🏷️ Tag & label colors – color-code categories, topics, or tags
  • 💬 Chat bubbles – visually distinguish different senders
  • 📊 Data visualizations – generate consistent palette from labels or IDs
  • 🖼️ Theming UI elements – change styling based on user/project/content
  • 🧾 Color-coded identifiers – visually distinguish IDs, usernames, emails
  • 📰 Blog post or card backgrounds – create dynamic, unique color cards for each post
  • 🗂️ Kanban boards or dashboards – assign colors to tasks or projects by title
  • 🎟️ Event/ticketing systems – auto-assign color badges per attendee or ticket

🤝 Contributing

Contributions are welcome! Feel free to open issues, suggest features, or submit pull requests.

📄 License

MIT License © [Prajwal Dhungana]