Why do we use shorthand properties in CSS?

A shorthand property sets several related properties in one line. We use them to write shorter and cleaner CSS.

/* long way */
margin-top: 10px;
margin-right: 20px;
margin-bottom: 10px;
margin-left: 20px;

/* shorthand */
margin: 10px 20px;

border: 2px solid #333;
background: #eee url("bg.png") no-repeat center;
font: italic bold 16px/1.5 Arial, sans-serif;

Common shorthands are margin, padding, border, background, font, flex and transition. Be careful: a shorthand also resets the values you do not write. See CSS Syntax.


Learn more about the similar topics:
Tutorials
CSS Units
CSS Text
CSS Fonts
CSS Links
CSS Lists
CSS Tables
Exercises & Assignments
Write CSS to style a heading (centre, uppercase, letter spacing)
Write CSS to style a table with zebra stripes
Interview Questions & Answers
Why do we use shorthand properties in CSS?
What is the difference between px, em, rem and % in CSS?