Performance: Margin utilities
Margin utilities affect layout calculation and paint performance by changing spacing around elements.
Jump into concepts and practice - no test required
<div class="mb-4"></div> <div class="mb-4"></div> <div></div>
<div class="m-4"></div> <div class="m-4"></div> <div class="m-4"></div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using m-4 on every element | Multiple style recalculations | Multiple reflows per element | High paint cost due to layout shifts | [X] Bad |
| Using mb-4 only on needed elements | Minimal style recalculations | Single reflow per container | Lower paint cost with stable layout | [OK] Good |
m-4 do to an element?m-4 means margin with a spacing scale value of 4, which equals 1rem (16px by default).m- sets margin, not padding. Padding uses p-.mt- prefix for margin-top, followed by the spacing scale number.mt-8 is valid and means margin-top of 2rem. Other options are invalid syntax.mx-6 my-2 in Tailwind CSS?mx-6 sets horizontal margins (left and right) to spacing scale 6 = 1.5rem. my-2 sets vertical margins (top and bottom) to spacing scale 2 = 0.5rem.mb8 does not work. What is the correct fix?mb-8.mb8 is invalid because it lacks the dash. Adding the dash fixes the syntax.mb8 to mb-8 -> Option Dmd: prefix applies styles at medium screen sizes and above.m-0 sets margin 0 on all sides for small screens.mx-12 sets horizontal margin to spacing scale 12 = 3rem. Using md:mx-12 applies this only on medium+ screens.