Style backgroundColor Property
Exemple
Définissez une couleur d'arrière-plan pour un document :
document.body.style.backgroundColor = "red";
Plus d'exemples "Essayez-le vous-même" ci-dessous.
Définition et utilisation
La propriété backgroundColor définit ou renvoie la couleur d'arrière-plan d'un élément.
Prise en charge du navigateur
Les nombres dans le tableau indiquent la première version du navigateur qui prend entièrement en charge la propriété.
Property | |||||
---|---|---|---|---|---|
backgroundColor | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Syntaxe
Renvoyez la propriété backgroundColor :
object.style.backgroundColor
Définissez la propriété backgroundColor :
object.style.backgroundColor = "color|transparent|initial|inherit"
Valeurs de propriété
Value | Description |
---|---|
color | Specifies the background color. Look at CSS Color Values for a complete list of possible color values |
transparent | Default. The background color is transparent (underlying content will shine through) |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Détails techniques
Valeur par défaut: | transparent |
---|---|
Valeur de retour : | Une chaîne, représentant la couleur d'arrière-plan |
Version CSS | CSS1 |
Plus d'exemples
Exemple
Définissez une couleur d'arrière-plan pour un élément <div> spécifique :
document.getElementById("myDiv").style.backgroundColor = "lightblue";
Exemple
Renvoie la couleur d'arrière-plan d'un élément <div> spécifique :
alert(document.getElementById("myDiv").style.backgroundColor);
Exemple
Renvoie la couleur de fond d'un document :
alert(document.body.style.backgroundColor);
Pages connexes
Tutoriel CSS : Arrière-plan CSS
Référence CSS : propriété background-color
Référence HTML DOM : propriété background