--- name: layout-margin description: Controlling element margins with spacing scale, negative values, logical properties, and space utilities --- # Margin Utilities for controlling an element's margin. ## Usage ### All sides Use `m-` to set margin on all sides: ```html
Margin on all sides
Larger margin
``` ### Individual sides Use `mt-`, `mr-`, `mb-`, `ml-`: ```html
Top margin
Right margin
Bottom margin
Left margin
``` ### Horizontal and vertical Use `mx-` for horizontal, `my-` for vertical: ```html
Horizontal margin
Vertical margin
``` ### Negative margins Prefix with dash for negative values: ```html
Negative top margin
Negative horizontal margin
``` ### Auto margins Use `m-auto` or directional auto margins for centering: ```html
Centered horizontally
Pushed to right
``` ### Logical properties Use `ms-` (margin-inline-start) and `me-` (margin-inline-end) for RTL support: ```html
Left margin in LTR
Right margin in LTR
Right margin in RTL
Left margin in RTL
``` ### Space between children Use `space-x-` or `space-y-` to add margin between children: ```html
01
02
03
01
02
03
``` ### Reversing space Use `space-x-reverse` or `space-y-reverse` with reversed flex directions: ```html
01
02
03
``` ### Custom values Use arbitrary values for custom margins: ```html
Custom margin
Custom calculation
``` ## Key Points - Spacing scale: `m-0` through `m-96` (and beyond) - Negative: prefix with dash (`-m-4`, `-mt-8`, `-mx-4`) - Auto: `m-auto`, `mx-auto`, `my-auto`, `mt-auto`, etc. - Logical: `ms-*` (start), `me-*` (end) adapt to text direction - Space utilities: `space-x-*`, `space-y-*` add margin to all children except last - Space reverse: `space-x-reverse`, `space-y-reverse` for reversed flex layouts - Limitations: Space utilities don't work well with grids or complex layouts - use `gap` utilities instead