String.prototype.fontcolor(color) returns an HTML string that wraps your text in a <font color="..."> tag. It is a deprecated HTML wrapper (legacy only) and does not create a live DOM node.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call string.fontcolor. Start with this line.
JavaScript
str.fontcolor(color)
Call
What it does
str.fontcolor(color)
Primary signature.
string.fontcolor(...)
Call with the arguments your case needs.
Built into JavaScript. Call fontcolor(...) on a string (or String instance) — no import required.
Library declarations
JavaScript
str.fontcolor(color)
Parameters
Parameter
Description
color
Required. Attribute value (coerced to string; not validated)
Return Value
Return Value
Description
*
HTML string with <font color>
JavaScript Examples
Example 1 — Named Color
Wrap text with a CSS color name and log the HTML string.
Create a real node.createElement("p") gives you a live element.
Set safe text.textContent avoids HTML injection risks from string-built tags.
Apply CSS.style.color = "red" is valid and themeable.
Prefer classes in apps. A CSS class or design token scales better than inline styles.
Compatibility
Browser & Runtime Support
String.prototype.fontcolor() is still widely implemented for compatibility, but it is deprecated. Do not use it in new projects.
✓ Deprecated · Legacy
String.fontcolor()
Available in modern browsers for old code. MDN recommends CSS color instead of building <font> tags.
LegacyCompatibility only
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
fontcolor()Avoid in new code
Bottom line: Recognize fontcolor() in legacy samples. For new UI, control text color with CSS color — never rely on the obsolete <font> element from HTML wrapper methods.
Frequently Asked Questions
fontcolor(color) returns an HTML string that wraps the text in a <font color="..."> tag. For example, "Hello".fontcolor("red") returns '<font color="red">Hello</font>'.
Yes. MDN marks all HTML wrapper methods as deprecated. The <font> element itself was removed from the HTML specification. Prefer CSS color instead.
A CSS color name (like "red") or a hexadecimal RGB triplet without # (like "FA8072" for salmon). The method does not validate the value — it just puts it in the attribute.
No. Strings are immutable. fontcolor() returns a new string containing HTML markup. The original text stays the same.
Double quotes in color are escaped as " so the generated attribute stays well-formed as HTML text.
Set CSS color on an element, for example element.style.color = "red", or use a CSS class / custom property. Do not build <font> tags with string methods.