The style
attribute introduces CSS to HTML.
The HTML style Attribute
The purpose of the style
attribute is to provide a common way to style all HTML elements.
Styles was introduced with HTML 4, as the new and preferred way to style HTML elements.
With HTML styles, styles can be added to HTML elements directly by using the style
attribute, or indirectly in separate style sheets.
HTML Style Examples
Style examples of background color, font family, color and size, text alignment are given next.
Style details will be discussed in the CSS.
style="background-color:yellow"
style="font-family:Times"
style="text-align:center"
Style attributes are used in HTML tags such as the following examples.
<body style="background-color:yellow">
<p style="font-family:courier; color:red; font-size:20px">
<h1 style="text-align:center">
Deprecated Tags and Attributes
In HTML 4, some tags and attributes are defined as deprecated.
Deprecated means that they will not be supported in future versions of HTML and XHTML.
These tags and attributes should be avoided:
Tags |
Description |
|
Attribute |
Description |
<center> |
Defines centered content. |
align |
Defines the alignment of text. |
<font> or <basefont> |
Defines HTML fonts. |
bgcolor |
Defines the background color. |
<s> or <strike> |
Defines strikeout text. |
color |
Defines the text color. |
<u> |
Defines underlined text. |
|
|
Demonstration
The following demonstration shows how the HTML script is displayed on the Web.