Need to generate color gradients for your application? This guide covers everything you need to know about creating beautiful gradients programmatically via API, including gradient types, color interpolation methods, and implementation examples in multiple languages.
What is a Color Gradient?
A color gradient is a smooth transition between two or more colors. Gradients are widely used in UI design, data visualization, and graphics to create depth, visual interest, and indicate progress or intensity.
For example, a gradient from #ff6b6b to #4ecdc4 creates a beautiful coral-to-teal transition perfect for backgrounds and buttons.
Gradient Types Explained
There are several types of gradients you can create:
Linear Gradient
Colors transition along a straight line, typically from top to bottom, left to right, or at any angle. Most commonly used in web design.
Radial Gradient
Colors radiate outward from a central point, creating a circular or elliptical effect. Great for spotlight effects and buttons.
Multi-Stop Gradient
Gradients with more than two colors, allowing complex color transitions with defined stop positions.
Using the Gradient Generator API
TinyFn provides a simple endpoint to generate color gradients:
GET https://api.tinyfn.io/v1/color/gradient?start=%23ff6b6b&end=%234ecdc4&steps=5
Headers: X-API-Key: your-api-key
{
"start": "#ff6b6b",
"end": "#4ecdc4",
"steps": 5,
"colors": [
"#ff6b6b",
"#d98f8a",
"#9fb39f",
"#77c0b1",
"#4ecdc4"
],
"css": "linear-gradient(90deg, #ff6b6b, #d98f8a, #9fb39f, #77c0b1, #4ecdc4)"
}
Parameters
| Parameter | Type | Description |
|---|---|---|
start |
string | Starting color in hex, RGB, or HSL format |
end |
string | Ending color in hex, RGB, or HSL format |
steps |
integer | Number of color stops to generate (default: 5) |
interpolation |
string | Color space for interpolation: rgb, hsl, lab (default: lab) |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/color/gradient?start=%23ff6b6b&end=%234ecdc4&steps=5',
{ headers: { 'X-API-Key': 'your-api-key' } }
);
const { colors, css } = await response.json();
console.log(colors); // ['#ff6b6b', '#d98f8a', '#9fb39f', '#77c0b1', '#4ecdc4']
console.log(css); // linear-gradient(90deg, #ff6b6b, ...)
Python
import requests
response = requests.get(
'https://api.tinyfn.io/v1/color/gradient',
params={
'start': '#ff6b6b',
'end': '#4ecdc4',
'steps': 5
},
headers={'X-API-Key': 'your-api-key'}
)
data = response.json()
print(data['colors']) # ['#ff6b6b', '#d98f8a', ...]
print(data['css']) # linear-gradient(...)
cURL
curl "https://api.tinyfn.io/v1/color/gradient?start=%23ff6b6b&end=%234ecdc4&steps=5" \
-H "X-API-Key: your-api-key"
Common Use Cases
- UI Backgrounds: Create eye-catching hero sections and card backgrounds
- Data Visualization: Generate heatmap color scales and chart colors
- Progress Indicators: Color-coded progress bars and loading states
- Brand Palettes: Generate color variations from brand colors
- Image Processing: Create gradient overlays and color maps
Best Practices
- Use LAB interpolation: Produces perceptually uniform gradients without muddy middle colors
- Test accessibility: Ensure text remains readable over gradient backgrounds
- Consider color blindness: Avoid red-green gradients for data visualization
- Cache CSS output: Store generated gradients to reduce API calls
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 Gradient Generator API
Get your free API key and start creating beautiful gradients in seconds.
Get Free API Key