Writing CSS

There are two ways to add CSS to your Web page: write up a style sheet or put CSS code into the style attribute of the tag that you want to format.

Writing a Style Sheet

A style sheet is a block of CSS code. It appears between style tags in an HTML document, or it exists as a separate file that you import into the HTML document. A style sheet consists of one or more style rules, or presentation instructions for the browser. A style rule, in turn, consists of a style selector, which is the element that you are formatting; and a style definition, which gives attribute/value pairs that tell the browser how to display the selector.

A style sheet looks something like this:

 <style type="text/css"> h1 { font-family: Arial; font-weight: ...

Get Web Design Garage 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.