CKTIS / CSS
CSS shorthand `margin`
`margin` sets a box’s physical outer margins in top, right, bottom, and left order.
Version: CSS modules; captured CSSWG editor index includes draft and obsolete features requiring review
Syntax
<'margin-top'>{1,4}margin sets a box’s physical outer margins in top, right, bottom, and left order.
The example applies four distinct values in a flex row: geometry exposes the left and top offsets and the right gap to a sibling, while computed style confirms all four sides.
Grammar: <'margin-top'>{1,4}.
One to four values expand by the clockwise rule. Block margins can collapse in normal flow but not in flex or grid; auto can absorb free space, negative values are allowed, and percentages use the containing block’s inline size.
Examples
<!doctype html>
<html lang="en"><meta charset="utf-8"><title>margin behavior</title>
<body><div id="row"><i id="first"></i><i id="second"></i></div><pre id="result"></pre><script>
const row=document.querySelector('#row'),first=document.querySelector('#first'),second=document.querySelector('#second');
row.style.cssText='display:flex;width:200px;height:100px;align-items:flex-start';first.style.cssText='display:block;width:20px;height:20px;margin:10px 20px 30px 40px';second.style.cssText='display:block;width:20px;height:20px';
const outer=row.getBoundingClientRect(),a=first.getBoundingClientRect(),b=second.getBoundingClientRect(),s=getComputedStyle(first);
document.querySelector('#result').textContent='offset='+Math.round(a.left-outer.left)+','+Math.round(a.top-outer.top)+'; gap='+Math.round(b.left-a.right)+'; sides='+[s.marginTop,s.marginRight,s.marginBottom,s.marginLeft].join(' ');
</script></body></html>Result
offset=40,10; gap=20; sides=10px 20px 30px 40px
The example was executed locally in an isolated, network-free Chrome session; the result comes from the browser CSS API.