Formatting with the Style Attribute

Every HTML element has a default style which is used when displaying the element on the web page. For example, a paragraph by default displays black text on a white background. To change the default style of an element, the style attribute is defined within the element tag.

You Try It: Style Attribute

Besides color, there are a number of other elements which can be styled using the style attribute. Think about some of the formatting you might do in a word processing document - changing the font, for example, or centering a title on a page. These can be controlled in html using the style attribute. Let's use the Try-It Editor again to do some additional formatting with the style attribute. Click the name of each attribute in this list and experiment with the style attributes: