The Exact Error
Invalid property value — background: linear-gradient(top, #fff, #000)
Or in DevTools:
Property ignored — invalid value (background-image)
Quick summary: The gradient function syntax is wrong — common mistakes include using the old top direction keyword without to (should be to bottom), missing commas between color stops, or applying a gradient to color instead of background.
Why This Error Happens
CSS gradients changed syntax between the early WebKit implementation and the final standard. Old code examples still circulate with pre-standard syntax that modern browsers reject.
Five causes:
1. Old direction syntax — top, left, right, bottom without the to keyword.
2. Missing comma between color stops — linear-gradient(red blue) is invalid.
3. Gradient on color property — Gradients are <image> values, not <color> values.
4. Prefixed vs unprefixed syntax difference — The old -webkit-linear-gradient() used a different direction convention.
5. Invalid color stop positions — Mixing units inconsistently.
Step-by-Step Diagnosis
Step 1 — Check direction syntax
/* OLD (invalid): */
background: linear-gradient(top, red, blue);
/* NEW (correct): */
background: linear-gradient(to bottom, red, blue);
background: linear-gradient(to right, red, blue);
Step 2 — Check comma placement
/* WRONG: */
background: linear-gradient(to right, red blue);
/* RIGHT: */
background: linear-gradient(to right, red, blue);
Step 3 — Verify the property name
/* WRONG — gradients on 'color': */
color: linear-gradient(to right, red, blue);
/* RIGHT: */
background: linear-gradient(to right, red, blue);
Solutions
Solution 1 — Fix direction keyword syntax
/* Old → New direction mapping:
top → to bottom
bottom → to top
left → to right
right → to left */
background: linear-gradient(to bottom, #ffffff, #000000);
background: linear-gradient(to right, #ff6b6b, #4ecdc4);
background: linear-gradient(to bottom right, #667eea, #764ba2);
Solution 2 — Use angle-based direction
background: linear-gradient(180deg, #ffffff, #000000); /* top to bottom */
background: linear-gradient(90deg, #ff6b6b, #4ecdc4); /* left to right */
background: linear-gradient(45deg, #667eea, #764ba2); /* diagonal */
Solution 3 — Multiple color stops
background: linear-gradient(to right, red, yellow, green);
background: linear-gradient(to right,
#fff 0%,
#e0e0e0 50%,
#000 100%
);
/* Hard stop (no blend): */
background: linear-gradient(to right, red 50%, blue 50%);
Solution 4 — Fix transparent color stops
/* WRONG — 'transparent' fades to black: */
background: linear-gradient(to right, #ff6b6b, transparent);
/* RIGHT — use rgba of the same color: */
background: linear-gradient(to right, #ff6b6b, rgba(255, 107, 107, 0));
Quick Reference
| Direction | Syntax |
|---|
| Top to bottom | linear-gradient(to bottom, ...) |
| Bottom to top | linear-gradient(to top, ...) |
| Left to right | linear-gradient(to right, ...) |
| Diagonal | linear-gradient(to bottom right, ...) |
Prevent This Error in the Future
1. Always use the to <direction> keyword syntax for direction-based gradients.
2. Test gradients in at least two browsers — Chrome and Firefox sometimes accept slightly different syntax.
3. Use a gradient generator to build the CSS visually and copy the correct syntax.
Use ToolNinja to Debug Faster
The CSS Gradient Generator lets you build gradients visually — drag color stops, choose directions, adjust angles — then copies the correct modern CSS syntax.
🔧 CSS Gradient — toolninja.io/tools/css-gradient