Need to invert colors for dark mode, contrast enhancement, or creative effects? This guide covers the Color Invert API, which calculates the inverse (negative) of any color by subtracting each RGB component from 255.
How Color Inversion Works
Color inversion calculates the negative of a color by subtracting each RGB component from 255:
- Formula: Inverted = RGB(255-R, 255-G, 255-B)
- Example: White (#FFFFFF) inverts to Black (#000000)
- Example: Red (#FF0000) inverts to Cyan (#00FFFF)
Invert vs Complement
Color inversion is different from complementary colors:
- Inversion: Subtracts from 255 (RGB-based)
- Complement: 180 degree rotation on color wheel (HSL-based)
For pure colors (red, green, blue, cyan, magenta, yellow), they're the same. For other colors, they differ.
Using the Color Invert API
TinyFn provides a simple endpoint for color inversion:
GET https://api.tinyfn.io/v1/color/invert
Headers: X-API-Key: your-api-key
{
"original": {
"hex": "#3498db",
"rgb": { "r": 52, "g": 152, "b": 219 },
"hsl": { "h": 204, "s": 70, "l": 53 }
},
"inverted": {
"hex": "#cb6724",
"rgb": { "r": 203, "g": 103, "b": 36 },
"hsl": { "h": 24, "s": 70, "l": 47 }
}
}
Parameters
| Parameter | Type | Description |
|---|---|---|
color |
string | Color in HEX (#RGB or #RRGGBB), RGB, or HSL format (required) |
format |
string | Output format: hex, rgb, hsl, all. Default: all |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/color/invert?' + new URLSearchParams({
color: '#3498db'
}),
{ headers: { 'X-API-Key': 'your-api-key' } }
);
const result = await response.json();
console.log(result.inverted.hex); // "#cb6724"
Python
import requests
response = requests.get(
'https://api.tinyfn.io/v1/color/invert',
params={'color': 'rgb(52, 152, 219)'},
headers={'X-API-Key': 'your-api-key'}
)
result = response.json()
print(result['inverted']['hex']) # "#cb6724"
cURL
curl "https://api.tinyfn.io/v1/color/invert?color=%233498db" \
-H "X-API-Key: your-api-key"
Common Use Cases
- Dark Mode: Calculate inverted colors for dark theme
- Accessibility: Create high-contrast text overlays
- Image Effects: Create negative image effects
- Hover States: Generate hover color variations
- Design Tools: Color manipulation in design applications
Best Practices
- Check contrast: Inverted colors aren't always readable; verify contrast ratios
- Consider perception: Gray colors invert to similar grays
- Test accessibility: Ensure inverted colors meet WCAG guidelines
- Combine with other adjustments: May need brightness/saturation tweaks
Use via MCP
Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:
{
"mcpServers": {
"tinyfn-color": {
"url": "https://api.tinyfn.io/mcp/color/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
See all color tools available via MCP in our Color MCP Tools for AI Agents guide.
Try the Color Invert API
Get your free API key and start inverting colors instantly.
Get Free API Key