Dieser Inhalt wurde automatisch aus dem Englischen übersetzt, und kann Fehler enthalten. Erfahre mehr über dieses Experiment.

View in English Always switch to English

<gradient>

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨Juli 2015⁩.

* Some parts of this feature may have varying levels of support.

Der <gradient> CSS Datentyp ist ein spezieller Typ von <image>, der aus einem progressiven Übergang zwischen zwei oder mehreren Farben besteht.

Probieren Sie es aus

background: linear-gradient(#f69d3c, #3f87a6);
background: radial-gradient(#f69d3c, #3f87a6);
background: repeating-linear-gradient(#f69d3c, #3f87a6 50px);
background: repeating-radial-gradient(#f69d3c, #3f87a6 50px);
background: conic-gradient(#f69d3c, #3f87a6);
<section class="display-block" id="default-example">
  <div id="example-element"></div>
</section>
#example-element {
  min-height: 100%;
}

Ein CSS-Gradient hat keine intrinsischen Dimensionen; d.h., er hat keine natürliche oder bevorzugte Größe und kein bevorzugtes Verhältnis. Seine konkrete Größe wird an die Größe des Elements angepasst, auf das er angewendet wird.

Syntax

Der <gradient> Datentyp wird mit einer der unten aufgeführten Funktionstypen definiert.

Linearer Verlauf

Lineare Verläufe ändern Farben progressiv entlang einer imaginären Linie. Sie werden mit der linear-gradient() Funktion erzeugt.

Radialer Verlauf

Radiale Verläufe ändern Farben progressiv von einem Mittelpunkt (Ursprung) aus. Sie werden mit der radial-gradient() Funktion erzeugt.

Kegelförmiger Verlauf

Kegelförmige Verläufe ändern Farben progressiv um einen Kreis. Sie werden mit der conic-gradient() Funktion erzeugt.

Wiederholender Verlauf

Wiederholende Verläufe duplizieren einen Verlauf so oft wie nötig, um ein gegebenes Gebiet zu füllen. Sie werden mit den Funktionen repeating-linear-gradient(), repeating-radial-gradient(), und repeating-conic-gradient() erzeugt.

Interpolation

Wie bei jeder Interpolation, die Farben umfasst, werden Verläufe im alpha-vormultiplizierten Farbraum berechnet. Dies verhindert unerwartete Grauschattierungen, wenn sowohl die Farbe als auch die Transparenz sich ändern. (Beachten Sie, dass ältere Browser dieses Verhalten möglicherweise nicht nutzen, wenn das Schlüsselwort transparent verwendet wird.)

Formale Syntax

<gradient> = 
<linear-gradient()> |
<repeating-linear-gradient()> |
<radial-gradient()> |
<repeating-radial-gradient()> |
<conic-gradient()> |
<repeating-conic-gradient()>

<linear-gradient()> =
linear-gradient( [ <linear-gradient-syntax> ] )

<repeating-linear-gradient()> =
repeating-linear-gradient( [ <linear-gradient-syntax> ] )

<radial-gradient()> =
radial-gradient( [ <radial-gradient-syntax> ] )

<repeating-radial-gradient()> =
repeating-radial-gradient( [ <radial-gradient-syntax> ] )

<conic-gradient()> =
conic-gradient( [ <conic-gradient-syntax> ] )

<repeating-conic-gradient()> =
repeating-conic-gradient( [ <conic-gradient-syntax> ] )

<linear-gradient-syntax> =
[ [ <angle> | <zero> | to <side-or-corner> ] || <color-interpolation-method> ]? , <color-stop-list>

<radial-gradient-syntax> =
[ [ [ <radial-shape> || <radial-size> ]? [ at <position> ]? ] || <color-interpolation-method> ]? , <color-stop-list>

<conic-gradient-syntax> =
[ [ [ from [ <angle> | <zero> ] ]? [ at <position> ]? ] || <color-interpolation-method> ]? , <angular-color-stop-list>

<side-or-corner> =
[ left | right ] ||
[ top | bottom ]

<color-interpolation-method> =
in [ <rectangular-color-space> | <polar-color-space> <hue-interpolation-method>? | <custom-color-space> ]

<color-stop-list> =
<linear-color-stop> , [ <linear-color-hint>? , <linear-color-stop> ]#?

<radial-shape> =
circle |
ellipse

<radial-size> =
<radial-extent> |
<length [0,∞]> |
<length-percentage [0,∞]>{2}

<position> =
<position-one> |
<position-two> |
<position-four>

<angular-color-stop-list> =
<angular-color-stop> , [ <angular-color-hint>? , <angular-color-stop> ]#?

<rectangular-color-space> =
srgb |
srgb-linear |
display-p3 |
display-p3-linear |
a98-rgb |
prophoto-rgb |
rec2020 |
lab |
oklab |
<xyz-space>

<polar-color-space> =
hsl |
hwb |
lch |
oklch

<hue-interpolation-method> =
[ shorter | longer | increasing | decreasing ] hue

<custom-color-space> =
<dashed-ident>

<linear-color-stop> =
<color> <color-stop-length>?

<linear-color-hint> =
<length-percentage>

<radial-extent> =
closest-corner |
closest-side |
farthest-corner |
farthest-side

<length-percentage> =
<length> |
<percentage>

<position-one> =
left |
center |
right |
top |
bottom |
x-start |
x-end |
y-start |
y-end |
block-start |
block-end |
inline-start |
inline-end |
<length-percentage>

<position-two> =
[ left | center | right | x-start | x-end ] && [ top | center | bottom | y-start | y-end ] |
[ left | center | right | x-start | x-end | <length-percentage> ] [ top | center | bottom | y-start | y-end | <length-percentage> ] |
[ block-start | center | block-end ] && [ inline-start | center | inline-end ] |
[ start | center | end ]{2}

<position-four> =
[ [ left | right | x-start | x-end ] <length-percentage> ] && [ [ top | bottom | y-start | y-end ] <length-percentage> ] |
[ [ block-start | block-end ] <length-percentage> ] && [ [ inline-start | inline-end ] <length-percentage> ] |
[ [ start | end ] <length-percentage> ]{2}

<angular-color-stop> =
<color> <color-stop-angle>?

<angular-color-hint> =
<angle-percentage> |
<zero>

<xyz-space> =
xyz |
xyz-d50 |
xyz-d65

<color-stop-length> =
<length-percentage>{1,2}

<color-stop-angle> =
[ <angle-percentage> | <zero> ]{1,2}

<angle-percentage> =
<angle> |
<percentage>

Beispiele

Beispiel für einen linearen Verlauf

Ein linearer Verlauf.

css
.linear-gradient {
  background: linear-gradient(
    to right,
    red,
    orange,
    yellow,
    green,
    blue,
    indigo,
    violet
  );
}

Beispiel für einen radialen Verlauf

Ein radialer Verlauf.

css
.radial-gradient {
  background: radial-gradient(red, yellow, dodgerblue);
}

Beispiel für einen kegelförmigen Verlauf

Ein Beispiel für einen kegelförmigen Verlauf.

css
.conic-gradient {
  background: conic-gradient(pink, coral, lime);
}

Beispiele für wiederholende Verläufe

Beispiele für wiederholende lineare und radiale Verläufe.

css
.linear-repeat {
  background: repeating-linear-gradient(
    to top left,
    pink,
    pink 5px,
    white 5px,
    white 10px
  );
}

.radial-repeat {
  background: repeating-radial-gradient(
    lime,
    lime 15px,
    white 15px,
    white 30px
  );
}

.conic-repeat {
  background: repeating-conic-gradient(lime, pink 30deg);
}

Spezifikationen

Specification
CSS Images Module Level 4
# gradients

Browser-Kompatibilität

Siehe auch