Document.fgColor is a deprecated instance property that gets or sets the document’s foreground text color as a string. Learn how legacy pages used it with bgColor, the Firefox default, the MDN-recommended CSS color replacement, and five examples with try-it labs.
01
Kind
Instance property
02
Type
string color
03
Status
Deprecated
04
Controls
Text / foreground
05
Replace
CSS color
06
Pairs with
bgColor
Fundamentals
Introduction
Before CSS took over page styling, scripts could tint an entire document with Document color properties: fgColor for text (foreground), bgColor for the page background, and link colors such as linkColor, vlinkColor, and alinkColor.
MDN’s recommended alternative today is the CSS color property—for example document.body.style.color = "red", or better, a stylesheet rule.
💡
Foreground = text color
“fg” stands for foreground. Setting fgColor aims at the document’s default text color, not borders or backgrounds.
Document.fgColor is deprecated but may still work for compatibility in some browsers. MDN recommends CSS color instead. Logos use the shared browser-image-sprite.png sprite from this project.
✓ Deprecated · Legacy
Document.fgColor
Legacy document foreground (text) color getter/setter — use CSS color in new code.
LegacyCompatibility only
Google ChromeCompatibility support · prefer CSS
Legacy support
Mozilla FirefoxCompatibility support · default #000000
Legacy support
Apple SafariCompatibility support
Legacy support
Microsoft EdgeChromium compatibility layer
Legacy support
OperaFollow Chromium behavior
Legacy support
Internet ExplorerHistorical legacy target
Legacy support
Document.fgColorAvoid in new code
Bottom line: Recognize document.fgColor in old scripts. For new text colors, use CSS color on body or a theme root — never document.fgColor.
Wrap Up
Conclusion
Document.fgColor is a deprecated way to get or set a document’s default text color. Learn it to maintain old code—then migrate to CSS color (and pair backgrounds with background-color, not bgColor, in new work).
Set text color with document.fgColor in new features
Assume every browser still honors the property
Use light text on light backgrounds
Mix legacy Document colors with modern CSS without testing
Rely on Firefox defaults as a cross-browser contract
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about document.fgColor
Deprecated text color API — prefer CSS color.
5
Core concepts
📄01
Means
text color
Foreground
⚠️02
Status
deprecated
MDN
🎨03
Type
string color
API
🚫04
Default
#000000
Firefox
✓05
Replace
CSS color
Modern
❓ Frequently Asked Questions
It gets or sets the foreground color — the text color — of the current document.
Yes. MDN marks Document.fgColor deprecated in the HTML specification. Prefer the CSS color property in new code.
A string color name (such as white or red) or a hexadecimal color (such as #ff0000).
MDN notes the default fgColor in Mozilla Firefox is black (#000000 in hexadecimal).
Use CSS color, for example document.body.style.color = "red", or preferably a stylesheet rule such as body { color: ... }.
No. Style text with CSS or design-system tokens. Learn fgColor only to read or migrate old scripts.
Did you know?
The same era that gave us document.fgColor also exposed <body text="..."> and bgcolor HTML attributes. All of those document-level color knobs were replaced by the CSS cascade—one of the biggest clarity wins in web styling history.