Setting the background color in JavaScript

JavaScript FAQ | JavaScript Colors FAQ  

Question: How do I change the document's background color?

Answer: To change the background color, set the document.bgcolor property. For example, this will change the background color to gray:

document.bgColor="#CCCCCC"  // set to gray
Try it now:
This select box was created using the following code:
<form name="bgcolorForm">Try it now: 
<select onChange="if(this.selectedIndex!=0)
document.bgColor=this.options[this.selectedIndex].value">
<option value="choose">set background color    
<option value="FFFFCC">light yellow
<option value="CCFFFF">light blue
<option value="CCFFCC">light green
<option value="CCCCCC">gray
<option value="FFFFFF">white
</select></form>

See also:
  • RGB to Hex color converter
  • Hex to RGB color converter
  • RGB to CMYK color converter  
  • Hex to CMYK color converter
  • RGB to HSV color converter
  • JavaScript Colors FAQ
  • Changing the color of HTML elements
  • Predefined color names
  • Applying another stylesheet to my page
  • Changing the mouse cursor style
  • Copyright © 1999-2012, JavaScripter.net.