Herramientas · CSS · Crear degradado CSS · Guías · Why Hand-Writing a CSS Gradient Rarely Looks Like What You Pictured
Why Hand-Writing a CSS Gradient Rarely Looks Like What You Pictured
You write background-image: linear-gradient(135deg, #ff7a59, #ffd166);, save the file, and reload the page - and the angle is wrong, or the colors don't blend the way you expected, or one color dominates way more of the space than you meant. This isn't a syntax mistake. It's that gradient CSS asks you to picture a visual result from a line of numbers, and almost nobody can do that reliably in their head, especially for anything past a simple two-color linear fade.
The angle number doesn't mean what it feels like it should mean
CSS gradient angles are measured clockwise from the top, where 0deg points straight up and 90deg points right - not from the horizontal the way you might expect from geometry class, and not from the direction the gradient's colors are "read" in. This alone trips people up constantly: 45deg feels like it should be a diagonal from bottom-left to top-right, and it is, but only because of that top-referenced convention, not because 45 degrees is intuitively "diagonal" in any direction-agnostic sense. Get the reference point wrong in your head and every angle you type will be rotated from what you expected.
Color stops aren't evenly spaced unless you say so
A gradient with two colors and no stop positions splits evenly across the whole span - simple enough. But add a third color, or specify positions like 0%, 20%, 100%, and the visual result stops being obvious from the syntax. A stop at 20% doesn't mean "20% of the way through the color blend" in some averaged sense - it means the gradient reaches pure that color at the 20% mark, then blends toward the next stop from there. Two color stops sitting close together produce a sharp transition; stops spread far apart produce a slow one. None of this is visible in the numbers unless you've built up a strong mental model of gradient math, which most people building a CSS layout have not, because they do this rarely enough that the model never sticks.
The same three numbers, two different reads
Degrees aren't even the only way to write an angle
To make matters more confusing, CSS also accepts keyword-based directions instead of a degree number: to right, to bottom left, to top, and so on. These read more intuitively than a number - "to right" is unambiguous in a way "90deg" isn't until you've memorized the convention - but they're not interchangeable with the equivalent-sounding degree value in every case. to right is equivalent to 90deg, but to bottom right is not the same as 135deg - the keyword form points toward the actual corner of the element regardless of its aspect ratio, while the degree form is a fixed angle that only points at the corner when the box happens to be square. On a wide rectangular element, to bottom right and 135deg visibly diverge. Knowing which syntax you're reading matters as much as knowing what the number means.
Radial and conic gradients compound the problem
Linear gradients are the easiest case, and they're already hard to picture. Radial gradients add a center position (nine named positions like "top left" or "center," or an explicit coordinate) that changes where the color rings emanate from - move it off-center and the whole shape shifts in a way that's hard to predict from the position keyword alone. Conic gradients rotate colors around a center point like a color wheel or a pie chart, starting from a chosen angle - genuinely difficult to reason about from syntax alone, since the mental model most people have for "gradient" is a straight-line fade, and conic breaks that model entirely.
The fallback line is a separate, easy-to-forget problem
Beyond getting the gradient itself right, a production stylesheet also needs a solid-color fallback for the rare case where background-image doesn't apply or an older tool can't render it - typically the first color stop's own solid value, set on background before the gradient overrides it. It's easy to get the gradient right and forget this line entirely, which is a real, separate mistake from getting the angle wrong.
What actually helps
The fix isn't getting better at mental gradient math - it's not doing the math in your head at all. Build the gradient visually, watch it render as you adjust the angle, stops, and colors, and copy out the resulting CSS once it looks right, rather than reverse-engineering syntax from a mental picture. The CSS gradient generator works this way: pick linear, radial, or conic, add or remove up to 8 color stops with live preview, position each one and set its opacity with a slider instead of typing a guess, and copy the finished CSS - including the fallback line - once it actually matches what you had in mind.
Once you're comfortable with linear gradients, the next guide covers building a radial gradient specifically, since the center-position math is its own small trap. And the fallback color mentioned above gets its own explanation in this guide, since it's easy to skip and genuinely matters. If you're picking the gradient's colors from scratch, the color palette generator is a natural first stop - a harmonious two- or three-color set makes a much better-looking gradient than colors picked independently.