Generic inline container for styling text with CSS. The modern replacement for <font>.
Learn more →
<font> ElementThe <font> element was used in early HTML to change the color, size, and typeface of text. It was one of the presentational elements that mixed content with styling, which modern web development separates using CSS.
<font color="red" size="5" face="Arial">Styled text</font>The <font> element supported three main attributes for controlling text appearance:
| Attribute | Description | Values |
|---|---|---|
color | Text color | Color name (e.g., red, blue) or hex value (e.g., #FF0000) |
size | Font size on a scale | 1 to 7 (default: 3), or relative values (+1, -2) |
face | Font typeface | Comma-separated list of font names (e.g., Arial, Helvetica) |
This example shows how the <font> element was used in older HTML documents:
The <font> element was deprecated and removed for several important reasons:
1. Separation of Concerns
HTML should describe the structure and meaning of content, not its presentation. Mixing styling directly into HTML makes code harder to maintain and update.
2. Poor Maintainability
Changing the appearance of a site required editing every single <font> tag. With CSS, you can update styles site-wide by changing a single stylesheet.
3. Limited Flexibility
The <font> element offered only basic styling options. CSS provides hundreds of properties for precise control over typography, including line-height, letter-spacing, font-weight, text-shadow, and more.
4. Accessibility Issues
The arbitrary size scale (1-7) didn’t respect user preferences for text size. Modern CSS units like em and rem scale with user settings, improving accessibility.
5. Performance
Inline styles in HTML increase page size. External CSS files can be cached by browsers, improving load times.
Use CSS properties to achieve the same effects with better control and maintainability.
Replace color attribute with the CSS color property:
Replace size attribute with the CSS font-size property:
Replace face attribute with the CSS font-family property:
Combine multiple font properties using the CSS font shorthand:
Here’s how to convert common <font> patterns to modern CSS:
<!-- Color only --><font color="red">Red text</font>
<!-- Size only --><font size="5">Large text</font>
<!-- Font face only --><font face="Arial">Arial text</font>
<!-- All attributes --><font color="blue" size="4" face="Verdana"> Styled text</font>
<!-- Nested fonts (common but messy) --><font size="6"> <font color="green"> <font face="Arial"> Multiple attributes </font> </font></font><!-- Color only --><span style="color: red;">Red text</span>
<!-- Size only --><span style="font-size: 24px;">Large text</span>
<!-- Font family only --><span style="font-family: Arial, sans-serif;">Arial text</span>
<!-- All properties combined --><span style="color: blue; font-size: 18px; font-family: Verdana, sans-serif;"> Styled text</span>
<!-- Better: use classes --><style> .highlight { color: green; font-size: 28px; font-family: Arial, sans-serif; }</style><span class="highlight">Multiple properties</span><!-- HTML file --><link rel="stylesheet" href="styles.css">
<p class="intro">This is introductory text</p><p class="highlight">This is highlighted text</p><p class="warning">This is warning text</p>.intro { font-size: 18px; font-family: Georgia, serif; color: #333; line-height: 1.6;}
.highlight { font-size: 20px; font-family: Arial, sans-serif; color: #0066cc; font-weight: bold;}
.warning { font-size: 16px; font-family: Arial, sans-serif; color: #cc0000; font-weight: bold;}The <font> element’s size attribute used values 1-7. Here’s an approximate conversion to modern CSS:
<font size> | Approximate CSS | Relative to Default |
|---|---|---|
1 | 10px or 0.63em | Smallest |
2 | 13px or 0.82em | Small |
3 | 16px or 1em | Default |
4 | 18px or 1.13em | Medium-large |
5 | 24px or 1.5em | Large |
6 | 32px or 2em | Larger |
7 | 48px or 3em | Largest |
The <font> element was supported by all major browsers during its lifetime:
| Browser | Supported | Removed |
|---|---|---|
| Chrome | 1-Current | Still renders (legacy support) |
| Firefox | 1-Current | Still renders (legacy support) |
| Safari | 1-Current | Still renders (legacy support) |
| Edge | 12-Current | Still renders (legacy support) |
| IE | 3-11 | Still rendered in IE11 |
Generic inline container for styling text with CSS. The modern replacement for <font>.
Learn more →
Embed CSS styles within an HTML document for controlling presentation. Learn more →
The <font> element appeared in early HTML specifications but was deprecated in HTML 4.01 and removed in HTML5:
HTML 4.01 Specification (Deprecated): https://www.w3.org/TR/html401/present/graphics.html#h-15.2.2
WHATWG HTML Living Standard (Removed): https://html.spec.whatwg.org/multipage/obsolete.html#font
MDN Web Docs (Deprecated): https://developer.mozilla.org/en-US/docs/Web/HTML/Element/font
For modern font styling, see the CSS Font properties: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_fonts