CSS Shorthand at a Glance - Basic CSS rules
(Page 2 of 8 )
Probably, as a seasoned Web developer, you already know the concepts. Still, let’s have a quick look at a sample CSS rule, showing the different sections of it, and the corresponding names for each part. The following image illustrates the anatomy of a CSS rule:

As depicted above, a CSS rule consists of a selector element or group of elements, and a property declaration section, which can include one or many properties, and the values tied to each one of them. At this point, these definitions should be very familiar to most of us, but it’s a useful reminder for those wishing to refresh some core concepts.
As we know, CSS rules allow us to define many property declarations for a selector, which usually is declared with a few lines of code. For instance, let’s say we want to apply a CSS style to a paragraph element. We do it in the following way:
p {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
}
The code listed above is a fairly common way to apply CSS styles to selectors, used by numerous developers in their Web pages. There are also many popular development tools such as Dreamweaver that will generate similar code when CSS styles are applied within a Web document. There is nothing wrong with this since it will work seamlessly on most browsers. However, the code might be greatly improved by just defining all of the selector property declarations in one line, using CSS shorthand:
p {
font: bold 12px "Arial", Helvetica, sans-serif;
}
We’ve redefined our CSS declaration using the "font" shorthand property, which allows us to set values for all of the above properties utilizing one line, cutting our code close to half the size. This technique will have a high impact on the overall style files, reducing their sizes considerably and making our site much more efficient and faster to display.
Let’s see in detail some of the most frequently used CSS shorthand properties, for easy implementation on our websites. This is not intended to be a full-blown CSS reference, as stated before. Instead, it can be a handy guide to quickly put CSS shortcuts into action and take advantage of their benefits. We’ll direct our attention to the most common CSS shorthand properties supported by today's browsers as well as some of the older ones.
Next: Font shorthand property >>
More Style Sheets Articles
More By Alejandro Gervasio