font element
font is obsolete presentational markup that still styles text through color, face and size hints; move the styling to CSS.
- Avoid
- Deprecated
- Severity
- DeprecatedFormally obsolete, but inert.
- Basis
- Obsoleted by the specA standard defined it, then removed it.
- Detectable
- YesMatched exactly. Autofixable when the rule carries a fix.
- Matches
fontElement rule, inside <body>.- Fix
- None — reports only
- Impacts
- Maintainability and Accessibility
- Related
element/basefont,element/big
<font color="red" face="Arial" size="5"> set the colour, typeface and size of a run of text
before stylesheets existed. It is the emblem of 1990s markup, and it lives on in email templates,
WYSIWYG editor output and content pasted in from word processors, because every one of those
tools could emit it.
Why avoid
It is obsolete and non-conforming. The HTML Standard lists font among the elements that “are
entirely obsolete, and must not be used by authors”, with basefont, big, center and tt,
and the instruction “Use appropriate elements or CSS instead.”
It still works, which is how it spreads. The Standard’s rendering rules keep all three attributes
alive as presentational hints: color sets the color property, face sets font-family, and
size sets font-size through “the rules for parsing a legacy font size”, the old 1-to-7 scale
with relative +2 and -1 steps. The page’s typography ends up spread across the content, one
element at a time. A stylesheet can’t restyle it in one place, and a redesign turns into an edit of
every document that contains it.
It is also forgiving in a way that hides mistakes. Its color attribute is read with “the rules
for parsing a legacy color value”, which “replace any character in input that is not an ASCII hex
digit with U+0030 (0)” rather than rejecting the value. A misspelled colour name doesn’t fail. It
turns into some other colour, where CSS would have discarded the invalid declaration.
And it means nothing. <font color="red">Payment failed</font> looks urgent, but the element
carries no semantics, so to a screen reader it’s just more text.
Use instead
Put the style in CSS, and the meaning in an element that has one:
.notice {
color: #b00020;
font-family: Georgia, serif;
font-size: 1.25rem;
}
<p class="notice"><strong>Payment failed.</strong> Please try again.</p>
Each attribute has a direct CSS counterpart: color becomes color, face becomes
font-family, and size becomes font-size.
Detectability
Fully detectable by tag name. There is no autofix: font still applies its colour, typeface and
size, so removing it would visibly change the text.
Resources
- HTML Standard — Non-conforming features —
fontis entirely obsolete: “Use appropriate elements or CSS instead.” - HTML Standard — Rendering: phrasing content —
color,faceandsizeonfontare presentational hints forcolor,font-familyandfont-size. - HTML Standard — Parsing a legacy color value — non-hex characters are replaced with
0instead of being rejected. - MDN —
<font>— deprecated; its attributes and their CSS replacements.
This page is generated from content/rules/element/font.md, the same file the linter is built from. Think the rule is wrong, or that browsers moved on? Say so — that is the most useful issue you can file.