CSS is used to for html styles.
Look! HTML Styles and colors
This text is in Verdana and red
This text is in Times and blue
This text is 30 pixels high
Styling HTML with CSS
CSS was introduced with HTML 4, to provide a common way to style HTML elements.
CSS styling can be added to HTML in the following ways
- in separate style sheet files (CSS files)
- in the style element in the HTML head section
- in the style attribute in single HTML elements.
Using the HTML Styles Attribute
It is time consuming and not very practical to style HTML elements using the style attribute.
The preferred way to add CSS to HTML, is to put CSS syntax in separate CSS files.
However, in this HTML tutorial we will introduce you to CSS using the style attribute. This is done to simplify the examples. It also makes it easier for you to edit the code and try it yourself.
HTML Styles Example - Background Color
The background-color property defines the background color for an element:
HTML Styles Example - Font, Color and Size
The font-family, color, and font-size properties defines the font, color, and size of the text in an element:
The style attribute makes the old <font> tag obsolete.
HTML Styles Example - Text Alignment
The text-align property specifies the horizontal alignment of text in an element:
The style attribute makes the old "align" attribute obsolete.
Deprecated Tags and Attributes
In HTML 4, several tags and attributes are deprecated. Deprecated means that they will not be supported in future versions of HTML and XHTML.
The message is clear: Avoid using deprecated tags and attributes!
These tags and attributes should be avoided:
|<center>||Deprecated. Defines centered content|
|<font> and <basefont>||Deprecated. Defines HTML fonts|
|<s> and <strike>||Deprecated. Defines strikethrough text|
|<u>||Deprecated. Defines underlined text|
|align||Deprecated. Defines the alignment of text|
|bgcolor||Deprecated. Defines the background color|
|color||Deprecated. Defines the text color|
For all of the above: Use html styles instead!