FoundationsSpacingBest Practices

Best Practices

Spacing tokens are identified in Shoreline by the prefix $space, followed by numeric suffixes that represent the space value in rems (value in pixels divided by 4). For example, the token with a 16px value is $space-4. The only exception is the token $space-gap, that represents the default spacing between elements in a page.

Spacing can be applied horizontally or vertically in any CSS property that receives a space value.

Usage

Relationships and hierarchy

  • Elements that are meaningfully related should be closer to each other, for example, a Checkbox and its label.
  • Elements arranged in the same spacing pattern are usually perceived as having similar weight, for example, options in a Checkbox Group.
  • Spacing can also define the relationships between groups of elements. For example, the space between form sections should have a higher value than the space between the form section title and a field.
  • Elements with more spacing around them are usually perceived as having a higher relevance on the interface, for example, the spacing around an error state of a Collection.

Space relationships Spacing within a Checkbox group and between form sections.

Visual rhythm

  • The visual rhythm of an interface is defined by pattern repetition. Spacing helps to create rhythm, improving predictability and scannability. It also allows you to draw the user’s attention to specific points by intentionally breaking the pattern.
  • The rhythm can be more predictable when elements within a screen have the same level of importance, such as in a Table.
  • The rhythm can also help organize elements that may have different levels of importance, such as in a dashboard.

Space visual rhythm Spacing between elements with the same level of importance.

Visual weight

  • The spacing scale can be applied horizontally or vertically. Depending on the visual weight of the element, sometimes using the same value on both axes doesn’t result in a balanced composition. In these scenarios, it’s necessary to optically adjust the spacing.
  • Observe if the components have a well-defined background (marked by a fill or stroke) or not. For example, the spacing value between primary and secondary Buttons should be larger than the spacing value between two tertiary Buttons.

Space visual weight Different spacing between components with and without a well-defined background.

Space visual weight Optical adjustment with the horizontal padding larger than the vertical padding.

Density

  • Tighter spacing, more dense: increases the level of scannability for large sets of data, such as in a Table.
  • Looser spacing, less dense: increases the level of hierarchy or helps define groups within an interface, such as Form sections.

Space density Tighter and looser spacing.

Examples

TokenUsage
$space-0Vertical:
- $text-body texts (Text + Text cell in Table)
- $text-action text → $text-body text (Name + Text cell in Table)
- $text-caption texts (Help Text and Error Text in fields)
$space-5Vertical:
- $text-body text → $text-caption text (Label and Help Text in a single Checkbox)
$space-1Vertical:
- Label → Input
- Input → $text-caption2 text (Help or Error Text)
- Trigger → Popover (Menu, Filter, DatePicker)

Horizontal:
- IconButtons normal (Admin Shell Topbar, DatePicker input buttons)
$space-2Vertical:
- Buttons normal (Empty State small)

Horizontal:
- Control → Label (Checkbox, Radio)
- Icon → Short text (Search)
- Normal Actions with a background (Buttons normal)
- Large Actions without a background (Tab List)
$space-3Vertical:
- Control Fields Group → $text-caption2 text (Checkbox Group or Radio Group help text)
- Content paddings top and bottom in narrow containers 120 - 239px
- Content padding-top in Pages without tabs in screens < 380px

Horizontal:
- Label → Control Fields (Checkbox Group, Radio Group)
- Icon → Long Text (Toast, Alert)
- Page Title → Tag Large (Page Header)
$space-4Vertical and Horizontal:
- The value of $space-gap
- Content paddings in containers 120 - 239px

Vertical:
- Controls in a group (Checkbox Group or Radio Group)
- Content padding-top in Pages without tabs in screens 380 - 559px
$space-5Horizontal:
- Controls in a group (Checkbox Group or Radio Group)

Vertical:
- Fields in a form section
- Content padding-top in Pages without tabs in screens > 560px
- Content paddings top and bottom in narrow containers 240 - 379px
$space-6Vertical and Horizontal:
- Content paddings in containers 240 - 379px

Vertical:
- Form section title → Fields
- Content paddings top and bottom in narrow containers 380 - 559px
$space-7Vertical and Horizontal:
- Content paddings in containers 380 - 559px

Vertical:
- Content paddings top and bottom in narrow containers 560 - 799px
$space-8Vertical and Horizontal:
- Content paddings in containers 560 - 799px

Vertical:
- Content paddings top and bottom in narrow containers 800 - 1600px
$space-10Vertical and Horizontal:
- Content paddings in containers 800 - 1600px

Vertical and Horizontal:
- Toast bottom and right margins
$space-12Vertical:
- Content padding-bottom in Pages in screens < 560px
$space-16Vertical:
- Form sections
$space-20Vertical:
- Content padding-bottom in Pages in screens > 560px
$space-24No scenarios mapped.
$space-28No scenarios mapped.
$space-32No scenarios mapped.