Constructing Style Rules

An embedded style sheet consists of a two-sided <style> tag placed in the <head> section of a document. Between the <head> and </head> tags, you define the rules for the various styles.

A style rule begins with the name of the tag or other element to which the style applies. For example, if you are creating a rule that will apply to all instances of the <h1> tag, start the rule with h1 (no brackets):

<style>
h1
</style>

Next, type a set of curly braces. You can place them on separate lines for greater readability if you want. Then place the rule inside the braces. For example, to create a rule that makes the text of a first-level heading red:

<style>
h1 {
color: red
}
</style>

If you have more than one rule to apply, such as ...

Get HTML and XHTML Step by Step now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.