document.bgColor gets or sets the background color of the current document (MDN). It is a legacy HTML-era API — useful when reading old scripts, not for new work.
Read the notes below before you get or set this property. Prefer feature detection when support is limited.
Syntax
Use document.bgColor. Start with this line.
JavaScript
document.bgColor / document.bgColor = color
Call
What it does
document.bgColor / document.bgColor = color
Primary signature.
Built into the browser. Read or assign document.bgColor — no import required.
Library declarations
JavaScript
document.bgColor / document.bgColor = color
Parameters
Parameter
Description
Color string
Optional. Name or hex (MDN)
Writable?
Required. Getter and setter (legacy)
Return Value
Return Value
Description
*
The current value of document.bgColor.
JavaScript Examples
Example 1 — Named Color (MDN)
MDN’s classic assignment: set the document background to "darkblue".
Set CSS via the DOM with document.body.style.backgroundColor.
Or use a stylesheet — body { background-color: … }.
Read computed styles with getComputedStyle when you need the final color.
Compatibility
Browser Support
Document.bgColor is a legacy HTML document color property. MDN marks it Deprecated. Many browsers still expose it for compatibility, but new code should use CSS background-color.
✓ Deprecated · Legacy
Document.bgColor
Gets or sets the document background color. Prefer CSS. Still present in many engines for old pages.
LegacyDeprecated
Google ChromeLegacy support
Yes*
Microsoft EdgeLegacy support
Yes*
Mozilla FirefoxLegacy (default white)
Yes*
Apple SafariLegacy support
Yes*
OperaLegacy support
Yes*
Internet ExplorerLegacy support
Yes*
bgColorLegacy
Bottom line: Supported widely for compatibility, but deprecated. See the MDN bgColor reference.
Frequently Asked Questions
MDN: it gets or sets the background color of the current document.
Yes. MDN marks Document.bgColor as Deprecated. Prefer CSS background-color (for example on body) in new code.
A string color name (such as darkblue) or a hexadecimal value (such as #ff0000). Setting null is converted to the empty string (MDN).
MDN notes the default bgColor in Firefox is white (#ffffff).
Use CSS background-color. Through the DOM: document.body.style.backgroundColor, or a stylesheet rule such as body { background-color: ... } (MDN).
No. Learn it to read or migrate legacy scripts. Style page backgrounds with CSS instead.