CSS Best Practice #2: Shorthand Properties

Write your CSS rules with shorthand properties. It keeps things simple and clean.

.example {
    /* long */
    padding-top:1px;
    padding-right:2px;
    padding-bottom:3px;
    padding-left:4px;

    /* short */
    padding:1px 2px 3px 4px;
}

To help you with the shorthand, Dustin Diaz took the time to put together a CSS shorthand guide. Way to go Dustin! Check the guide for in-depth descriptions, examples, and Dustins \”quirky facts\” (such as shorthand defaults).

SitePoint CSS Reference is another source for shorthand properties, or any property in general, you should/could/would use.

One thought on “CSS Best Practice #2: Shorthand Properties”

  1. I’ve seen cases where the shorthand has only two properties or uses the keyword “auto” or “inherit”. Can you explain the different types of shorthand? Details, man! Details!

Leave a Reply

Your email address will not be published. Required fields are marked *