Spacing

PrimeFlex provides various spacing utilities to modify an element's layout.

Classes

The spacing classes use the {property}{position}-{value} syntax whereas for responsive values {breakpoint}:{property}{position}-{value} format is used.

Property

Property can either be a margin or a padding.

  • m: margin
  • p: padding
Position

Position are available for the individual sides, the x-y axis or blank for the shortand of all sides.

  • t: top
  • b: bottom
  • l: left
  • r: right
  • x: left and right
  • y: top and bottom
  • blank: all sides
Value

Value field varies from 0 to 6 where default value of the $spacer is 1rem. The special auto value is available to margins only and used to center elements.

  • 0: $spacer * 0
  • 1: $spacer * .25
  • 2: $spacer * .5
  • 3: $spacer * 1
  • 4: $spacer * 1.5
  • 5: $spacer * 2
  • 6: $spacer * 3
  • 7: $spacer * 4
  • 8: $spacer * 5
  • auto: auto margin
Breakpoint

Breakpoints define how the spacing should be defined depending on the screen size. Design is mobile first so smaller values can also apply to larger values e.g. md also applies to lg or xl if they are not explicitly defined.

  • sm: small screens e.g. phones
  • md: medium screens e.g. tablets
  • lg: large screens e.g. notebooks
  • xl: larger screens .e.g monitors
Use Case 1

Spacing is a handy utility when elements wrap when screen size get smaller. In example below, when buttons wrap they are displayed on top of each other whereas with spacing this issue can easily be resolved.

Without Spacing
With Spacing
Use Case 2

Spacing utilities also work seamlessly with responsive PrimeFlex grid utilty. Example below demonstrates a case where on a smaller screen inputs receive a margin to position themselves separately in stacked mode, reduce the dimension of the window to view the difference.

Without Spacing
With Spacing