HTML DOM Style backgroundColor Property | JavaScript change background color
ExampleSetabackgroundcolorforadocument:document.body.style.backgroundColor="red";TryitYourself»[1]More"TryitYourself"examplesbelow.DescriptionThebackgroundColorpropertysetsorreturnsthebackgroundcolorofanelement.SyntaxReturnthebackgroundColorproperty:object.style.backgroundColorSetthebackgroundColorproperty:object.style.backgroundColor="color|transparent|initial|inherit"PropertyValuesValueDescriptioncolorSpecifiesthebackgroundcolor.LookatCSSColorValues[2]foracompletelistofpossiblecolorvaluest...
ExampleSet a background color for a document:
document.body.style.backgroundColor = "red";
Try it Yourself »[1]More "Try it Yourself" examples below.
DescriptionThe backgroundColor property sets or returns the background color of an element.
SyntaxReturn the backgroundColor property:
object.style.backgroundColor
Set the backgroundColor property:
object.style.backgroundColor = "color|transparent|initial|inherit"
Property Values Value Description color Specifies the background color. Look at CSS Color Values[2] 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[3] inherit Inherits this property from its parent element. Read about inherit[4] Technical Details Default Value: transparent Return Value: A String, r...