Style Rules - HTML

All style rules follow the same basic format:

selector { property1: value1; property2: value2; ...propertyN: valueN; }

Note that the formatting of CSS rules is very exact and follows these guidelines:

✦ The selector is followed by the formatting property definitions, which are enclosed in braces ({ }).
✦ A colon separates each property/value pair. Note that values that include spaces should be enclosed in double quotes, as in the following example:

font-family: “Times NewRoman”;

✦ Each property/value pair ends with a semicolon.

Tip Technically, the last property/value pair of a style definition need not end in a semicolon. However, it is good practice to end all your property/value pairs with a semicolon.

The selector is the elements that the style should be used on. The properties are all formatting properties of the selected elements that should be set to the associated values. A very simple example of a style rule follows:

h1 { color: Red; }

The selector (h1) causes this rule to be applied to all <h1> elements. The color property affects the font color of matching elements—in this case, the font color is set to red.
You can specify multiple selectors to apply to the same style definition—you separate the selectors with commas. For example, if you wanted all heading tags (1 through 6) to render as red text, you could use the following definition:

h1, h2, h3, h4, h5, h6 { color: red; }

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

HTML Topics