HTML text Attribute
The obsolete HTML text attribute was historically used on the <body> element to set the default color of text throughout a document.
text attribute is obsolete and should not be used in modern HTML. Use the CSS color property to control text color.
Historical Syntax
The text attribute was placed on the <body> element and used a color value to specify the document's default text color.
<body text="navy">
Older HTML also allowed color values such as hexadecimal notation:
<body text="#000080">
Historical Elements
The obsolete text attribute was associated with the <body> element.
| Element | Historical Purpose |
|---|---|
<body> |
Specified the default foreground color used for text in the document. |
Historical Use
Before CSS became the standard way to control presentation, authors could place color attributes directly on the <body> element.
<body text="#333333">
<h1>Garden Guide</h1>
<p>Learn how to care for your plants throughout the year.</p>
</body>
In supporting browsers, the text value established the default text color for the document. Other presentational body attributes could separately control the page background and the colors of hyperlinks.
Why It Became Obsolete
The text attribute mixed visual presentation with the HTML document structure. Modern webpages separate content and structure from presentation by using CSS for colors and other visual styles.
CSS also provides much greater control because text colors can be applied to the entire document, individual sections, specific elements, classes, and different interaction states.
Modern Alternative
Use the CSS color property instead of the obsolete text attribute.
Historical HTML
<body text="#333333">
...
</body>
Modern CSS
body {
color: #333333;
}
The color property sets the foreground color of an element's text. When applied to <body>, the color is inherited by descendant elements unless another CSS rule specifies a different color.
Learn More About CSS Colors
The CSS tutorials explain how to control text colors and specify color values:
- CSS Font Color - Control the color of text with the CSS
colorproperty. - CSS Color Values - Learn about the different ways colors can be written in CSS.
Legacy Browser Support
The text attribute was supported by older browsers as a presentational attribute on the <body> element.
Browsers may continue to recognize the attribute when displaying older webpages, but it is non-conforming and should not be used in new or updated HTML. Use the CSS color property instead.
For additional information about historical browser compatibility, visit Can I Use? . Search for the HTML element or attribute you want to check. Search results can include related HTML features, element attributes, APIs, and other technologies, so select the result that most closely matches the legacy feature you are researching.
Related Attributes
Other obsolete presentational attributes historically used to control document colors include:
bgcolor- Historically controlled the background color of the document or certain elements.link- Historically controlled the color of unvisited hyperlinks.vlink- Historically controlled the color of visited hyperlinks.alink- Historically controlled the color of active hyperlinks.color- Historically controlled colors on certain presentational elements.
Specifications
The text attribute on the <body> element is obsolete and must not be used by authors. CSS should be used to control the foreground color of document content. See the WHATWG HTML Living Standard for information about obsolete and non-conforming features.
