Tag selectors—sometimes called type
selectors—are extremely efficient styling tools, since they apply to every occurrence
of an HTML tag on a Web page. With them, you can make sweeping design changes to a
page with very little effort. For example, when you want to format every paragraph of
text on a page using the same font, color, and size, you merely create a style using
p (as in the <p> tag) as the selector. In essence, a
tag selector redefines how a browser displays a particular tag.
Prior to CSS, in order to format text, you had to wrap that text in a <font>
tag. To add the same look to every paragraph on a page, you often had to use the
<font> tag multiple times. This process was a lot of work, and required a lot
of HTML, making pages slower to download and more time-consuming to update. With tag
selectors you don't actually have to do anything to the HTML—just create
the CSS rule, and let the browser do the rest.
Tag selectors are easy to spot in a CSS rule, since they bear the exact same
name as the tag they style—p, h1, table, img, and so on. For
example, in Figure 3-2, the
h2 selector (top) applies some font styling to all <h2>
tags on a Web page (bottom).
As Figure 3-2 makes clear, tag
selectors don't get the less than (<) and greater than (>) symbols that
surround HTML tags. So when you're writing a rule for the
<p> tag, for example, just type the tag's
name—p.
Tag selectors have their downsides, however. What if you want