You can create CSS gradients in modern sites with something as simple as:
background-image: linear-gradient(red, orange);
The goal is to recreate this gradient in SVG, so what percentages are being used by default for each CSS stop?
We tinkered with different percentages (e.g., 50/50, 25/75) with the code below, but none of these experiments produced the same gradient. The closest was 10/90, but could someone confirm the default percentages used if you omit them?
div {
height: 100px;
background-color: red;
background-image:
linear-gradient(
red 50%,
orange 50%
);
}
Per your post, to reproduce the gradient in SVG, define your linear gradient in the svg
<defs/>
element.See the snippet below (the css only applies to the html divs).
When you have 2 colors the percentages are
0%
and100%
If we check the specification we can see read:
And then
And the full set of rules:
The first rule is trivial. The second rules means that we should logically have an incrementation. So if we have something like
linear-gradient(red 20%, blue 10%, yellow 5%)
it will get transformed tolinear-gradient(red 20%, blue 20%, yellow 20%)
. The third rule will simply position non positionned color to be spaced equally between two positionned colors.So if we have multiple colors without position it will be something like this:
And in case we have some defined positions we will have this:
More complex cases: