User Rating 0.0
Total Usage 0 times
Category CSS Tools
Input CSS (Shorthand)
Output CSS (Longhand)
Properties expanded: 0 Lines: 00
Is this tool helpful?

Your feedback helps us improve.

About

CSS shorthand properties compress multiple declarations into one line. A single margin: 10px 20px expands to four distinct properties. Getting the expansion order wrong causes layout bugs that are difficult to trace in production. This tool parses your CSS rules and expands every recognized shorthand - margin, padding, border, background, font, flex, animation, transition, inset, border-radius, and more - into their canonical longhand equivalents following the CSS specification's value resolution order.

The converter handles 1-to-4 value box-model expansion (top, right, bottom, left), compound shorthands like border where value types are detected by grammar rather than position, and logical properties such as margin-inline and padding-block. It preserves !important flags, comments, and unrecognized properties verbatim. Note: ambiguous shorthand values (e.g., a single keyword valid as both a font-family and font-weight) are resolved using the CSS specification's greedy parsing heuristic, which may differ from edge-case browser behavior.

css converter shorthand to longhand css expander css properties css tools web development css parser

Formulas

Box-model shorthands (margin, padding, border-width, border-style, border-color, inset) follow a clockwise expansion pattern starting from top:

Given values V = [v1, v2, ..., vn]
{
n = 1: top = right = bottom = left = v1n = 2: top = bottom = v1, right = left = v2n = 3: top = v1, right = left = v2, bottom = v3n = 4: top = v1, right = v2, bottom = v3, left = v4

For compound shorthands like border, value assignment uses type detection rather than positional order. The parser checks each token against known keyword sets: border-style keywords (solid, dashed, dotted, etc.), border-width keywords (thin, medium, thick) or length units, and treats the remaining token as border-color. Two-axis shorthands (overflow, gap, place-items) follow a simpler pattern: 1 value maps to both axes, 2 values map to block/inline (or x/y) respectively. The border-radius shorthand accepts an optional / separator for elliptical radii, expanding each axis independently using the 1 - 4 box-model rule above.

Where vn = individual value token from the shorthand declaration, n = count of whitespace-separated values provided.

Reference Data

Shorthand PropertyLonghand ExpansionsValue CountSpec Reference
marginmargin-top, margin-right, margin-bottom, margin-left1 - 4CSS Box Model L3
paddingpadding-top, padding-right, padding-bottom, padding-left1 - 4CSS Box Model L3
borderborder-width, border-style, border-color (then each → 4 sides)1 - 3CSS Backgrounds L3
border-topborder-top-width, border-top-style, border-top-color1 - 3CSS Backgrounds L3
border-widthborder-top-width, border-right-width, border-bottom-width, border-left-width1 - 4CSS Backgrounds L3
border-styleborder-top-style, border-right-style, border-bottom-style, border-left-style1 - 4CSS Backgrounds L3
border-colorborder-top-color, border-right-color, border-bottom-color, border-left-color1 - 4CSS Backgrounds L3
border-radiusborder-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius1 - 4 (/ 1 - 4)CSS Backgrounds L3
outlineoutline-width, outline-style, outline-color1 - 3CSS UI L3
backgroundbackground-color, background-image, background-repeat, background-position, background-attachment1 - 5CSS Backgrounds L3
fontfont-style, font-variant, font-weight, font-size, line-height, font-family2+ (complex)CSS Fonts L3
list-stylelist-style-type, list-style-position, list-style-image1 - 3CSS Lists L3
overflowoverflow-x, overflow-y1 - 2CSS Overflow L3
flexflex-grow, flex-shrink, flex-basis1 - 3CSS Flexbox L1
flex-flowflex-direction, flex-wrap1 - 2CSS Flexbox L1
gaprow-gap, column-gap1 - 2CSS Box Align L3
place-itemsalign-items, justify-items1 - 2CSS Box Align L3
place-contentalign-content, justify-content1 - 2CSS Box Align L3
place-selfalign-self, justify-self1 - 2CSS Box Align L3
insettop, right, bottom, left1 - 4CSS Logical Props L1
margin-inlinemargin-inline-start, margin-inline-end1 - 2CSS Logical Props L1
margin-blockmargin-block-start, margin-block-end1 - 2CSS Logical Props L1
padding-inlinepadding-inline-start, padding-inline-end1 - 2CSS Logical Props L1
padding-blockpadding-block-start, padding-block-end1 - 2CSS Logical Props L1
transitiontransition-property, transition-duration, transition-timing-function, transition-delay1 - 4 per layerCSS Transitions L1
animationanimation-name, animation-duration, animation-timing-function, animation-delay, animation-iteration-count, animation-direction, animation-fill-mode, animation-play-state1 - 8 per layerCSS Animations L1
columnscolumn-width, column-count1 - 2CSS Multi-column L1
text-decorationtext-decoration-line, text-decoration-style, text-decoration-color1 - 3CSS Text Decoration L3

Frequently Asked Questions

The CSS specification defines border as an unordered shorthand. The parser classifies each token by type: length values or width keywords (thin, medium, thick) map to border-width, style keywords (solid, dashed, dotted, double, groove, ridge, inset, outset, none, hidden) map to border-style, and everything else maps to border-color. Missing components receive their initial values (medium, none, currentColor respectively). This grammar-based approach matches how browsers parse the property.
Yes. For example, the border shorthand first splits into border-width, border-style, and border-color. Each of those is itself a 4-side shorthand, which the tool then expands into border-top-width, border-right-width, border-bottom-width, border-left-width, and so on. The result is 12 fully longhand declarations from a single border line.
The border-radius property accepts the pattern a b c d / e f g h where the values before the slash define horizontal radii and those after define vertical radii. The converter splits on the / character, applies the 1-to-4 box-model expansion independently to each group, then combines them as border-top-left-radius: h-val v-val for each corner. If no slash is present, horizontal and vertical radii are identical.
Unrecognized properties pass through verbatim. The converter only modifies declarations whose property name matches its internal shorthand dictionary. Comments, custom properties (--var), and unknown vendor-prefixed properties are preserved exactly as written. This ensures the output CSS remains functionally equivalent to the input.
The font shorthand requires font-size and font-family at minimum. The converter detects the size/line-height pattern (e.g., 16px/1.5) by splitting on the / character within that token. Preceding values are matched against font-style keywords (italic, oblique), font-variant (small-caps), and font-weight (bold, 100-900). Everything after the size/line-height token is treated as font-family. Missing optional components are set to their initial values: normal for style, variant, and weight.
The parser strips the !important flag from the shorthand value string before expansion, then appends it to every generated longhand declaration. This matches the CSS cascade behavior where a shorthand !important applies to all its longhands. The flag is preserved character-for-character to maintain compatibility with minified or irregular formatting.
Yes. The converter processes full CSS including selectors, media queries, and other at-rules. It walks each declaration block, expands recognized shorthand properties within their rule context, and preserves the overall stylesheet structure. Nested at-rules like @media and @supports are handled recursively.