Using a style attribute

One way to specify style is by adding a style attribute (style) to an element. The attribute value consists of one or more declarationsA specification of style as property:value., separated by semicolons.

Here a style attribute has been added to a paragraph element. There are two declarations, one with propertyAn aspect of an element that can be styled. color and valueThe specific style for a property (CSS) or for an attribute (HTML). green and the other with property font-style and italic (notice that the value is written as italic, not as italics).

<p style="color:green; font-style:italic"></p>

In general, an element can have any number of declarations included. Notice that the declarations are separated by semicolons and that all of the declarations together are put in quotation marks.

Although this is the most straight-forward method, since it is best practice to separate content and style, the style attributeExtra information added to an element. is the least preferred choice in most situations. It is worth learning as you may encounter it in looking at pages that others have developed.

Try the following:

  • Add a style attribute to the second paragraph.
  • Change the value of color using another name of a colour.
  • Change the value of font-style to normal or oblique. (It may be hard to see the difference between italic and oblique.)

Throughout this module you will learn more properties and values.

Note:

Hints:

  • undefined
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
<!DOCTYPE html>
<html lang="en">
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX