--- title: repeating-linear-gradient slug: Web/CSS/repeating-linear-gradient() translation_of: Web/CSS/repeating-linear-gradient() ---
{{ CSSRef() }}
A função CSS repeating-linear-gradient
cria uma {{cssxref("<image>")}} de repetidos gradientes. Isso funciona da mesma forma, e recebe os mesmos argumentos dos gradientes lineares básicos, como descrito em {{ cssxref("linear-gradient") }}, mas ele automaticamente repete as paradas das cores infinitamente em ambas as direções, com suas posições trocadas por múltiplos da diferença entre a posição da última parada de cor e a posição da primeira.
The consequence is that an end color of a gradient always coincide with a start color. If both are not identical, this will result in a sharp transition.
Like any other gradient, a repeating CSS linear gradient is not a CSS <color>
but an image with no intrinsic dimensions; that is, it has no natural or preferred size, nor ratio. Its concrete size will match the one of the element it applies to.
Mozilla currently only supports CSS gradients as values of the {{ Cssxref("background-image") }} property, as well as within the shorthand {{ Cssxref("background") }}. You specify a gradient value instead of an image URL.
Formal grammar: repeating-linear-gradient( [ <angle> | to <side-or-corner> ,]? <color-stop> [, <color-stop>]+ ) \---------------------------------/ \----------------------------/ Definition of the gradient line List of color stops where<side-or-corner> = [left | right] || [top | bottom]
and<color-stop> = <color> [ <percentage> | <length> ]?
repeating-linear-gradient( 45deg, blue, red ); /* A repeating gradient on 45deg axe starting blue and finishing red */ repeating-linear-gradient( to left top, blue, red); /* A repeating gradient going from the bottom right to the top left starting blue and finishing red */ repeating-linear-gradient( 0deg, blue, green 40%, red ); /* A repeating gradient going from the bottom to top, starting blue, being green after 40% and finishing red */
<side-or-corner>
left
or right
, and the second one the vertical side, top
or bottom
. The order is not relevant and each of the keyword is optional.to top
, to bottom
, to left
and to right
are translated into the angles 0deg
, 180deg
, 270deg
, 90deg
respectively. The others are translated into an angle that let the starting-point to be in the same quadrant than the described corner and so that the line defined by the starting-point and the corner is perpendicular to the gradient line. That way, the color described by the <color-stop>
will exactly apply to the corner point. This is sometimes called the "magic corner" property. The end-point of the gradient line is the symmetrical point of the starting-point on the other direction of the center box.<angle>
<color-stop>
background: repeating-linear-gradient(to bottom right, red, red 5px, white 5px, white 10px);
Specification | Status | Comment |
---|---|---|
{{ SpecName('CSS3 Images', '#repeating-gradients', 'repeating-linear-gradient()') }} | {{ Spec2('CSS3 Images') }} |
Feature | Firefox (Gecko) | Chrome | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support (on {{ cssxref("background") }} and {{ cssxref("background-image") }}) | {{ CompatGeckoDesktop("1.9.2") }}{{ property_prefix("-moz") }}[3] {{ CompatGeckoDesktop("16") }} |
10.0 (534.16){{ property_prefix("-webkit") }} [2][3] | 10.0 [1] | 11.10{{ property_prefix("-o") }} [3] | 5.1{{ property_prefix("-webkit") }}[2][3] |
On any properties that accept {{cssxref("<image>")}} | {{ CompatNo() }} | {{ CompatVersionUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatVersionUnknown() }} |
Legacy webkit syntax{{ non-standard_inline() }} | {{ CompatNo() }} | 3{{ property_prefix("-webkit") }} [2] | {{ CompatNo() }} | {{ CompatNo() }} | 4.0{{ property_prefix("-webkit") }}[2] |
Legacy from syntax (without to ){{ non-standard_inline() }} |
{{ CompatGeckoDesktop("1.9.2") }}{{ property_prefix("-moz") }} [4] Removed in {{ CompatGeckoDesktop("16") }} |
10.0 (534.16){{ property_prefix("-webkit") }} [2] | 10.0 | 11.10{{ property_prefix("-o") }}[4] | 5.1{{ property_prefix("-webkit") }}[2] |
to syntax |
{{ CompatGeckoDesktop("10") }}{{ property_prefix("-moz") }}[4] {{ CompatGeckoDesktop("16") }} |
{{ CompatNo() }} | 10.0 | 11.60{{ property_prefix("-o") }}[4] Presto 2.12 will remove the prefix. |
{{ CompatNo() }} |
[1] Internet Explorer 5.5 through 9.0 supports proprietary filter: progid:DXImageTransform.Microsoft.Gradient()
filter.
[2] WebKit since 528 supports the legacy -webkit-gradient(linear,…)
function. As of WebKit 534.16, it also supports the standard gradient syntax. Unlike in Gecko, in legacy WebKit you cannot specify both a position and angle in -webkit-linear-gradient()
. You can achieve the same effect by offsetting the color stops.
[3] Gecko, Opera & Webkit considers {{cssxref("<angle>")}} to start to the right, instead of the top. I.e. it considered an angle of to start to the right, instead of the top. I.e. it considered an angle of 0deg
as a direction indicator pointing to the right. This is different from the latest specification where an angle of 0deg
as a direction indicator points to the top.
[4] Firefox 3.6 and Opera 11.10 implemented, prefixed, an early syntax where the starting corner or side was indicated without the to
keyword, and effectively considered as a from position. The to
syntax has been added in Firefox 10 and Opera 11.60 , at first without removing the deprecated syntax and translation between the two is trivial:
-moz-repeating-linear-gradient(to top left, blue, red);
is the same as:
-moz-repeating-linear-gradient(bottom right, blue, red);
The legacy syntax, without to
, is planned to go away when the prefix is removed.