
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
invert-color
Advanced tools
© 2018, Onur Yıldırım (@onury). MIT License.
Generates inverted (opposite) version of the given color. (<1KB)
This passes a long test suite of Adobe Photoshop CC inverted colors...
Generating exactly the same results with it.

npm i invert-color
// Node, CommonJS
const invert = require('invert-color');
// ES2015, JSNext
import invert from 'invert-color';
// TypeScript
import invert, { RGB, RgbArray, HexColor, BlackWhite } from 'invert-color';
For UMD in browser, use lib/invert.min.js.
See other exports.
invert(color[, bw])color : String|Array|Objectbw : Boolean|Object#000000) or white (#ffffff), according to the luminance of the original color. You can set custom black/white values (and/or luminance threshold) by passing an object.invert('#000') // —> #ffffff
invert('#282b35') // —> #d7d4ca
// input color as RGB array or object
invert([69, 191, 189]) // —> #ba4042
invert({ r: 249, g: 119, b: 121 }) // —> #068886
// amplify to black or white
invert('#282b35', true) // —> #ffffff
// amplify to custom black or white color
invert('#282b35', { black: '#3a3a3a', white: '#fafafa' }) // —> #fafafa
// amplify with custom luminance threshold (default is invert.defaultThreshold = ~0.179)
invert('#282b35', { black: '#3a3a3a', white: '#fafafa', threshold: 0.01 }) // —> #3a3a3a
invert.asRGB(color[, bw])Invert and output result as RGB object.
invert.asRGB('#fff') // —> { r: 0, g: 0, b: 0 }
invert.asRgbArray(color[, bw])Invert and output result as RGB array.
invert.asRgbArray('#000') // —> [255, 255, 255]
bw option
This is useful in case, you need to create contrast (i.e. background vs foreground, for better readability). The animation at the top is a demonstration.
Clone original project:
git clone https://github.com/onury/invert-color.git
Install (dev) dependencies:
npm install
Add tests into test/unit.test.ts and run:
npm run cover
Travis build should pass, coverage should not degrade.
main, package.json now also defines module, jsnext:main and browser.threshold: number to BlackWhite options (interface). Fixes #16.invert.defaultThreshold constant..asRGB() - alias of .asRgbObject().MIT.
FAQs
Generates inverted (opposite) version of the given color.
We found that invert-color demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.