Shorthand Properties: How They Reset Values and the Order of Their Parts
How shorthands such as margin, font, background and flex expand into longhands, why omitted parts reset to initial values, the one-to-four value pattern for sides, value orders that trip people up, and shorthands with the cascade and var().
kvi5hnuCode Sprout team member8 min readOn this page
A shorthand property sets several other properties, its longhands, in one declaration. margin sets margin-top, margin-right, margin-bottom and margin-left. border sets twelve longhands: a width, style and color for each side, plus a reset of border-image. Shorthands save a lot of typing, but they have two habits that cause bugs: they reset what you leave out, and some of them depend on the order of their values.
Shorthands expand into longhands
The browser replaces a shorthand declaration with its longhands before the cascade runs:
.card { padding: 1rem 1.5rem; }
/* is exactly the same as */
.card {
padding-top: 1rem; padding-right: 1.5rem;
padding-bottom: 1rem; padding-left: 1.5rem;
}
DevTools show this: in the Styles pane, a shorthand has a triangle that expands into its longhands, and the Computed tab lists only longhands.
Because the cascade works on longhands, the order of declarations matters:
.card { padding: 1rem; padding-left: 2rem; } /* left 2rem, others 1rem */
.card { padding-left: 2rem; padding: 1rem; } /* all 1rem: the shorthand resets the left */
The usual pattern is shorthand first, then longhands to adjust it.
Omitted values are reset, not left alone
When you leave a part out of a shorthand, the browser doesn't skip it. It sets that longhand to its initial value:
h2 { font-weight: 700; }
.section-title { font: 1.5rem Georgia, serif; }
An <h2 class="section-title"> isn't bold. font expanded to font-style: normal; font-variant: normal; font-weight: normal; font-stretch: normal; font-size: 1.5rem; line-height: normal; font-family: Georgia, serif, and its font-weight: normal beats the h2 rule because the class is more specific.
h2 { font-weight: 700; color: #8a3b12; margin: 0.4rem 0; }
.with-font { font: 1.5rem Georgia, serif; } /* weight reset to normal */
.with-longhands { font-size: 1.5rem; font-family: Georgia, serif; }
.bg { background-color: #fde7d6; padding: 0.5rem; }
.bg-reset { background: linear-gradient(#f4c95d, #f4c95d) left / 6px 100% no-repeat; } /* color reset */
The shorthands that cause this most often:
fontresets weight, style, variant, stretch and line height, and also hidden longhands that it can't even set, such asfont-variant-numeric,font-kerningandfont-feature-settings. Afont-variant-numeric: tabular-numsset earlier is lost. Usefontonly for base styles, such as onbody, and longhands elsewhere.backgroundresetsbackground-colortotransparent, along with the image, position, size, repeat, attachment, origin and clip.borderresetsborder-imagetonone, which isn't one of its visible parts.transitionandanimationreset the timing function, delay and other parts you leave out.list-style,outline,text-decoration,grid,flexandinsetwork the same way.
Sometimes that's useful: background: none reliably clears everything about a background.

None of these are errors, so nothing warns you. The last panel's computed font-family shows the browser took bold serif as a family name.
Values for four sides: clockwise from the top
margin, padding, border-width, border-style, border-color, inset and scroll-margin take one to four values, going clockwise from the top: top, right, bottom, left. A missing value copies the opposite side:

| Declaration | Top | Right | Bottom | Left |
|---|---|---|---|---|
padding: 1rem | 1rem | 1rem | 1rem | 1rem |
padding: 1rem 2rem | 1rem | 2rem | 1rem | 2rem |
padding: 1rem 2rem 0 | 1rem | 2rem | 0 | 2rem |
padding: 1rem 2rem 0 3rem | 1rem | 2rem | 0 | 3rem |
The three-value form trips people up: it means top, sides, bottom.

The last two panels contain the same two declarations in opposite orders, and only the first keeps the wide left side.
The logical shorthands take up to two values, the start and the end of one axis: margin-block: 1rem 2rem and padding-inline: 1.5rem (article 47). They adapt to the writing direction, and they're often clearer than four values.
border-radius also goes clockwise, but by corners, starting top-left: border-radius: 8px 0 rounds the top-left and bottom-right. A slash separates horizontal and vertical radii (article 41).
Other value orders
Not all shorthands follow one pattern:
| Shorthand | Order | Example |
|---|---|---|
background-position, box-shadow and text-shadow offsets, translate | horizontal, then vertical (x y) | box-shadow: 4px 2px 8px #0003 |
gap | row gap, then column gap | gap: 1rem 2rem |
place-items, place-content, place-self | block axis (align), then inline axis (justify) | place-items: center start |
overflow | x, then y | overflow: hidden auto |
grid-area | row start, column start, row end, column end | grid-area: 1 / 2 / 3 / 4 |
flex | grow, shrink, basis | flex: 1 1 0% |
Positions and offsets use x then y, like coordinates. gap and the place- properties are the reverse: vertical first, matching rows before columns. When in doubt, check the property's MDN page, or look at the longhands in DevTools.
Shorthands with strict grammars
Some shorthands accept their parts in any order, because each kind of value is distinct: border: 1px solid #ccc and border: #ccc solid 1px are the same. Others are strict:
fontrequires a size and a family, in that order, and the family must come last. Style, variant and weight may come before the size, and a line height may follow it after a slash:font: italic 700 1rem/1.5 Georgia, serif. Without a size or family, the declaration is invalid. Put a keyword after the size, as infont: 1rem bold serif, and the browser readsbold serifas a font family name: no error, just the wrong result.backgroundallows a color only in the last layer, andbackground-sizeonly directly after the position, after a slash:background: url(paper.png) center / cover no-repeat, #f4efe6.flexhas special one-value forms:flex: 1means1 1 0%,flex: automeans1 1 auto,flex: nonemeans0 0 auto(article 62).
!important and var() in shorthands
!importanton a shorthand makes every longhand important:margin: 0 !importantsets four important declarations.var()in a shorthand is resolved when the value is computed, because the browser can't know at parse time which part each variable fills. Until then the longhands are "pending substitution". It works fine for styling, but scripts that readelement.style.marginTopget an empty string, and if the variable turns out to be invalid, every longhand of that shorthand becomes invalid at computed-value time (article 27).
What's current
- New shorthands keep arriving with new features:
insetfortop,right,bottomandleft, logicalmargin-blockandpadding-inline,place-items, and individual transforms (translate,rotate,scale) that aren't part oftransform. - The
fontshorthand also resets newer font longhands, such asfont-optical-sizingandfont-variation-settings, so the reset trap grows with each new font feature.
Common questions
Why did my background shorthand remove my background color?
Every omitted part is reset to its initial value, and the initial value of background-color is transparent. Include the color in the shorthand, or set background-color after it.
Should I avoid shorthands?
No. They're shorter and clearer. Just know what each one resets, and use longhands when you only mean to change one part, especially for font and background in components.
What does padding: 10px 20px 5px mean?
Top 10px, left and right 20px, bottom 5px.
Why is gap: 1rem 2rem vertical first, when box-shadow: 4px 2px is horizontal first?
They come from different traditions. Offsets and positions use x, y coordinates. Grid and alignment properties list rows (the block axis) before columns (the inline axis). There's no single rule, so look at the longhands in DevTools when unsure.
Summary
- Shorthands expand into longhands before the cascade, so a shorthand after a longhand resets it.
- Omitted parts of a shorthand are set to their initial values.
font,backgroundandborderreset more than they show. - Four-side shorthands go clockwise from the top. Missing values copy the opposite side.
- Positions and offsets are x then y, while
gapandplace-*are vertical first. fontneeds a size and a family, with the family last.backgroundaccepts a color only in the last layer.!importantapplies to every longhand.var()in a shorthand is resolved at computed-value time.
Practice questions
What are the four margins of margin: 0 auto 2rem?
Answer
Top 0, right and left auto, bottom 2rem. The three-value form is top, sides, bottom.
Why don't large prices get tabular digits, and how do you fix it?
.price { font-variant-numeric: tabular-nums; }
.price.large { font: 700 1.5rem system-ui, sans-serif; }
Answer
The font shorthand resets font-variant-numeric to normal, and .price.large is more specific, so it wins. Use longhands, as in .price.large { font-weight: 700; font-size: 1.5rem; }, or repeat font-variant-numeric after the shorthand.
What's wrong with font: 1rem bold Georgia, serif;?
Answer
The weight must come before the size. After the size, bold Georgia is read as an unquoted family name, so the browser looks for a font called "bold Georgia", falls back to serif, and the text isn't bold. Write font: bold 1rem Georgia, serif;.
Write a background shorthand with an image paper.png that covers the element, centered, not repeated, over a color #f4efe6.
Answer
background: url(paper.png) center / cover no-repeat #f4efe6;
Previous: Global Keywords: inherit, initial, unset, revert, revert-layer and all
Next: Cascade Layers: @layer, Layer Order and Taming Specificity

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.