This kind of CSS declaration is called inline because it is written insid e the opening tag
of an element. In line CSS isn’t very usefu l. In order to set or change some property of
all the elements o f the same type on on e page, you must write a declarations for e ach
of the elements separate ly. If you have lots of pages, y ou will really work yourself up
into a lather to style all of the elements.
In practice, you will exclusively use CSS rules (also called styles). A rule co nsists
of a selector and a declaration block. A declaration b lock is simply one or more
declarations enclosed within a pair of curly brackets. However, the real secret hides
in a selector, which we are going to unravel later. For n ow, we’ll u se the simple st of
selectors, which is simply the name of the HTML element you want to style. H ere’s
an example of a CSS rule:
Selector Declaration Block
First Declar ation Second Declar ation
Property Value Property Value
h1 { color: blue; width: 200p x; }
With the h1 selector, you select all the main hea ders in a d ocument and apply the
declarations within the declaratio n block to all of them simultan eously, which saves
you a lot of work.
Mike: Where do we put a rule to make it work?
Professor: You have two possibilities. T he first one is c alled an internal style shee t,
meaning that y ou place CSS rules in the same document you’re styling. CSS rules
come inside a <s tyle> HTML element placed inside docu ment’s <head>. Most d e-
signers plac e <style> elements just b efore th e closing </head> tag. For example:
<head>
<!-- ...
Here come other metadata elements not shown
in this example. ... -->
<style>
h1 { /* Selector and opening brace */
color: blue; /* First declaration */
width: 200px; /* Second declaration */
} /* Closing brace */
</style>
</head>
In the above exam ple, I used comments to explain different parts of the rule. Note
that, inside a <style> element, you should write CSS an d not HTML code. Differ-
ently from HTML, a CSS comment starts with a slash-asterisk pair (/*) and ends with
an asterisk-slash pair (*/). A comment can, of course, span over multiple lines. Same
as in HTML, comments are completely ignored by the browser. Remember that you
can use comments—apart from clarifying parts o f complicated CSS code or making
general remark s ab out the code—also for temporarily switching off certain declara-
40 Meeting 3. Presentation