# @csstools/postcss-image-function

> Generate a solid-color image from any color

Latest version **1.0.3** (published 2026-09-06) · MIT-0 license · 0 weekly downloads

## Install

```sh
npm install @csstools/postcss-image-function
pnpm add @csstools/postcss-image-function
yarn add @csstools/postcss-image-function
bun add @csstools/postcss-image-function
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2026-09-06 |
| First published | 2026-05-13 |
| Weekly downloads | 0 |
| License | MIT-0 |
| TypeScript types | none |
| Module format | ESM |
| Node | >=20.19.0 |
| Dependencies | 4 |
| Unpacked size | 6.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1052 |
| Maintainers | jonathantneal, alaguna, romainmenke |
| Keywords | csswg, fallback, image function, postcss-plugin |

## Links

- npm: https://www.npmjs.com/package/@csstools/postcss-image-function
- Repository: https://github.com/csstools/postcss-plugins
- Homepage: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-image-function#readme
- Issues: https://github.com/csstools/postcss-plugins/issues
- Funding: https://github.com/sponsors/csstools
- npm.io page: https://npm.io/package/@csstools/postcss-image-function

## Dependencies (4)

- [@csstools/utilities](https://npm.io/package/@csstools/utilities.md) ^3.0.0
- [@csstools/css-tokenizer](https://npm.io/package/@csstools/css-tokenizer.md) ^4.0.0
- [@csstools/css-parser-algorithms](https://npm.io/package/@csstools/css-parser-algorithms.md) ^4.0.0
- [@csstools/postcss-progressive-custom-properties](https://npm.io/package/@csstools/postcss-progressive-custom-properties.md) ^5.1.3

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2026-09-06
- 1.0.2 — 2026-08-15
- 1.0.1 — 2026-06-28
- 1.0.0 — 2026-05-13

## README

# PostCSS Image Function [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][PostCSS]

`npm install @csstools/postcss-image-function --save-dev`

[PostCSS Image Function] lets you easily generate a solid-color image from any color following the [CSS Images 4 Specification].

```css
.foo {
	background-image: image(transparent);
}

.foo {
	--bg-image: image(transparent);
}

/* becomes */

.foo {
	background-image: linear-gradient(transparent,transparent);
}

.foo {
	--bg-image: linear-gradient(transparent,transparent);
}
```

## Usage

Add [PostCSS Image Function] to your project:

```bash
npm install postcss @csstools/postcss-image-function --save-dev
```

Use it as a [PostCSS] plugin:

```js
const postcss = require('postcss');
const postcssImageFunction = require('@csstools/postcss-image-function');

postcss([
	postcssImageFunction(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);
```



## Options

### preserve

The `preserve` option determines whether the original notation
is preserved. By default, it is not preserved.

```js
postcssImageFunction({ preserve: true })
```

```css
.foo {
	background-image: image(transparent);
}

.foo {
	--bg-image: image(transparent);
}

/* becomes */

.foo {
	background-image: linear-gradient(transparent,transparent);
	background-image: image(transparent);
}

.foo {
	--bg-image: linear-gradient(transparent,transparent);
}

@supports (background-image: image(red)) {
.foo {
	--bg-image: image(transparent);
}
}
```

[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
[css-url]: https://cssdb.org/#image-function
[discord]: https://discord.gg/bUadyRwkJS
[npm-url]: https://www.npmjs.com/package/@csstools/postcss-image-function

[PostCSS]: https://github.com/postcss/postcss
[PostCSS Image Function]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-image-function
[CSS Images 4 Specification]: https://drafts.csswg.org/css-images-4/#funcdef-image

---
_Source: https://npm.io/package/@csstools/postcss-image-function · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
