CSS Selectors

Selectors are used to specify the element(s) to which the rule should be applied. We can select elements by HTML tag, id or class.

Element (or type) Selectors

Id Selectors

We use an id selector to choose exactly one element on the page. id selectors are prefixed with a "#" in the style element. Needless to say(??), the same id should not be used for more than one element on the page. If you want to select more than one element on a page, use a class.

Class Selectors

We use a class selector to choose (typically) several elements on the page. Class selectors are prefixed with a "." in the style element.

Decendant Selectors

These are also known as descendant selectors. Notice that in this page only the em elements that are contained in p elements are coloured blue ...

Additional Information

Try to choose meaningful names for id's and classes. Remember that theses names are case-sensitive.

Summary