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 🙏

© 2026 – Pkg Stats / Ryan Hefner

css-utility-functions

v1.1.1

Published

A collection of reusable CSS custom native functions using the @function syntax

Readme

CSS Utility Functions

A collection of reusable CSS custom native functions using the new @function syntax.

⚠️ Experimental Feature: CSS @function is currently experimental. Check browser compatibility before using in production.

Installation

npm install css-utility-functions

Or download and include in your project.

Usage

Option 1: Use Bundled Version (Recommended)

/* All functions in one file */
@import 'css-utility-functions';

/* Or use minified version */
@import 'css-utility-functions/dist/index.min.css';

Option 2: Import Individual Functions

@import 'css-utility-functions/src/alpha.css';
@import 'css-utility-functions/src/fluid.css';
/* ... import only what you need */

Option 3: Development (Source Files)

@import './src/index.css';

Building

# Install dependencies
npm install

# Build bundled version
npm run build

# Build minified version
npm run build:min

# Build both
npm run build:all

# Watch for changes
npm run watch

Available Functions

Color Utilities

--alpha()

Creates a semi-transparent version of any color.

.overlay {
  background: --alpha(#6366f1, 0.2);
}

--lighten() / --darken()

Adjust a color's lightness. Use decimal values (0.1 = 10%, 0.2 = 20%).

.btn:hover {
  background: --lighten(var(--btn-bg), 0.15);
}

--saturate() / --desaturate()

Adjust a color's saturation/chroma. Use decimal values (0.4 = 40%, 1.0 = 100%).

.vibrant {
  background: --saturate(var(--primary), 0.4);
}

--mix()

Blend two colors by percentage.

.tinted {
  background: --mix(white, var(--brand), 90%);
}

--contrast-text()

Auto-select black or white text for optimal contrast.

.badge {
  background: var(--badge-color);
  color: --contrast-text(var(--badge-color));
}

Spacing & Sizing

--space()

Consistent spacing scale (4px base).

.card {
  padding: --space(4);        /* 1rem */
  gap: --space(2);            /* 0.5rem */
}

--fluid()

Responsive sizing that scales smoothly between viewports.

h1 {
  font-size: --fluid(1.5rem, 4rem);
}

--ratio-height()

Calculate height from width and aspect ratio.

.video-thumb {
  width: 320px;
  height: --ratio-height(320px, 16, 9);  /* 180px */
}

Visual Effects

--shadow()

Elevation shadows based on level (1-5). Optionally control shadow direction with angle parameter.

.card {
  box-shadow: --shadow(2);
}

.lit-from-top-right {
  box-shadow: --shadow(3, oklch(0% 0 0 / 0.15), 135deg);
}

.lit-from-left {
  box-shadow: --shadow(2, oklch(0% 0 0 / 0.1), 180deg);
}

--bevel()

Inset elevation shadows for embossed/debossed effects. Optionally control light source direction with angle parameter.

.pressed-button {
  box-shadow: --bevel(2);
}

.lit-from-top {
  box-shadow: --bevel(2, oklch(0% 0 0 / 0.1), 270deg);
}

.input-field {
  box-shadow: --bevel(1, oklch(0% 0 0 / 0.08), 90deg);
}

Layout Utilities

--neg()

Negate a value (useful for negative margins).

.pull-up {
  margin-top: --neg(var(--header-height));
}

Unit Conversion

--to-rem() / --to-px()

Convert between pixels and rem (assumes 16px base).

.legacy {
  font-size: --to-rem(18);    /* 1.125rem */
  width: --to-px(10);         /* 160px */
}

Quick Reference

| Function | Purpose | Example | |----------|---------|---------| | Color Utilities ||| | --alpha() | Color transparency | --alpha(blue, 0.3) | | --lighten() | Increase lightness | --lighten(#333, 0.2) | | --darken() | Decrease lightness | --darken(#ccc, 0.1) | | --saturate() | Boost saturation | --saturate(gray, 0.5) | | --desaturate() | Reduce saturation | --desaturate(#f00, 0.3) | | --mix() | Blend colors | --mix(red, blue, 25%) | | --contrast-text() | Auto text color | --contrast-text(var(--bg)) | | --grayscale() | Remove saturation | --grayscale(#6366f1) | | --invert() | Invert lightness | --invert(#fff)#000 | | --complement() | Complementary color | --complement(blue) → orange | | Spacing & Sizing ||| | --space() | Spacing scale | --space(4)1rem | | --fluid() | Viewport-responsive sizing | --fluid(1rem, 3rem) | | --fluid-container() | Container-responsive sizing | --fluid-container(1rem, 2rem) | | --ratio-height() | Aspect ratio calc | --ratio-height(100px, 16, 9) | | Visual Effects ||| | --shadow() | Elevation shadows | --shadow(3) | | --bevel() | Inset shadows (emboss/deboss) | --bevel(2) | | --diagonal-lines() | Diagonal line pattern | --diagonal-lines(--angle: 45deg) | | Layout Utilities ||| | --neg() | Negate value | --neg(2rem)-2rem | | Math Utilities ||| | --lerp() | Linear interpolation | --lerp(100px, 500px, 0.5) | | --circle-x() / --circle-y() | Circle coordinates | --circle-x(100px, 45deg) | | --modular() | Typographic scale | --modular(2, 1rem, 1.25) | | --poly-angle() | Polygon vertex angle | --poly-angle(6, 0) | | Unit Conversion ||| | --to-rem() | px → rem | --to-rem(16)1rem | | --to-px() | rem → px | --to-px(2)32px | | Logic Operations ||| | --not() | Boolean negation | --not(1)0 | | --and() | Logical AND | --and(1, 1)1 | | --or() | Logical OR | --or(0, 1)1 | | --xor() | Exclusive OR | --xor(1, 0)1 | | --nand() | NOT AND | --nand(1, 1)0 | | --nor() | NOT OR | --nor(0, 0)1 | | --xnor() | Exclusive NOR | --xnor(1, 1)1 |


Browser Support

CSS @function is an experimental feature. Check MDN for current browser support.

License

MIT (or your preferred license)