String.prototype.fontsize(size) returns an HTML string that wraps your text in a <font size="..."> 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.fontsize. Start with this line.
JavaScript
str.fontsize(size)
Call
What it does
str.fontsize(size)
Primary signature.
string.fontsize(...)
Call with the arguments your case needs.
Built into JavaScript. Call fontsize(...) on a string (or String instance) — no import required.
Library declarations
JavaScript
str.fontsize(size)
Parameters
Parameter
Description
size
Required. Attribute value (coerced to string; not validated)
Return Value
Return Value
Description
*
HTML string with <font size>
JavaScript Examples
Example 1 — Absolute Size (1–7)
Wrap text with a classic HTML font size and log the HTML string.
<font size="7">Hello, world</font>
<font size="1">Hello, world</font>
Hello, world
How It Works
Start with text.text holds "Hello, world".
Pick a size.7 is the largest classic value; 1 is the smallest.
Get a string. The return value is markup text, not a painted element.
Original stays put. Strings are immutable — text is unchanged.
Example 2 — Relative Size (+n / -n)
Pass a relative size string. Historically these were relative to default size 3.
JavaScript
console.log("Title".fontsize("+2"));
// '<font size="+2">Title</font>'
console.log("Note".fontsize("-1"));
// '<font size="-1">Note</font>'
// No validation — any value is pasted into the attribute:
console.log("X".fontsize("huge"));
// '<font size="huge">X</font>'
Create a real node.createElement("p") gives you a live element.
Set safe text.textContent avoids HTML injection from string-built tags.
Apply CSS.style.fontSize accepts modern units (em, rem, px, …).
Prefer classes in apps. A type scale / CSS class is easier to maintain than inline styles.
Compatibility
Browser & Runtime Support
String.prototype.fontsize() is still widely implemented for compatibility, but it is deprecated. Do not use it in new projects.
✓ Deprecated · Legacy
String.fontsize()
Available in modern browsers for old code. MDN recommends CSS font-size 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
fontsize()Avoid in new code
Bottom line: Recognize fontsize() in legacy samples. For new UI, control text size with CSS font-size — never rely on the obsolete <font> element from HTML wrapper methods.
Frequently Asked Questions
fontsize(size) returns an HTML string that wraps the text in a <font size="..."> tag. For example, "Hello".fontsize(7) returns '<font size="7">Hello</font>'.
Yes. MDN marks all HTML wrapper methods as deprecated. The <font> element itself was removed from the HTML specification. Prefer CSS font-size instead.
Historically an integer from 1 to 7, or a relative string like "+3" or "-2" (relative to the default size 3). The method does not validate the value — it just puts it in the attribute.
No. Strings are immutable. fontsize() returns a new string containing HTML markup. The original text stays the same.
Double quotes in size are escaped as " so the generated attribute stays well-formed as HTML text.
Set CSS font-size on an element, for example element.style.fontSize = "2em" or "1.25rem", or use a CSS class / type scale. Do not build <font> tags with string methods.