Space helps organize content, permitting consistent density and visual order that telegraphs our brand.
The Morningstar Design System applies space within and between components—even differently sized ones—to consistently render harmonious visual displays. The spatial standards and concepts described below are woven through the entire library and can help product teams compose custom views and components.
System components are composed with consistent spatial applications using a few reusable concepts: insetting, stretching an inset, stacking, and separating items inline.
An inset applies padding equal on all four sides to block or inline elements.
Apply inset
constants to component and element padding, like an item in a List Group or a cell in a Data Table.
Variable Name | Value | Result |
---|---|---|
$mds-space-inset-xs | 4px |
Text
|
$mds-space-inset-s | 6px |
Text
|
$mds-space-inset-m | 8px |
Text
|
$mds-space-inset-l | 12px |
Text
|
$mds-space-inset-xl | 16px |
Text
|
<div class="mds-doc-space__inset-example">Text</div>
.mds-doc-space__inset-example {
@include mds-text-crop();
background-color: $mds-background-color-dark;
color: $mds-text-color-primary-on-dark;
padding: $mds-space-inset-m;
}
Some element arrangements conform to inset spacing conventions, but need left-most and right-most elements to align with an element's edge. In that case, zero out the left edge of the left-most cell and right edge of the right-most cell, as is done within the Data Table component.
Ticker |
Price($) |
Selected |
---|---|---|
FSHBX | 8.60 | 0 |
HAINX | 60.32 | -0.59 |
Many System components “stretch” the inset, adding more padding to the left and right of the contained text and/or elements.
Apply inset-stretch
constants to component and element padding.
Variable Name | Value | Result |
---|---|---|
$mds-space-inset-stretch-s | 6px 12px |
Text
|
$mds-space-inset-stretch-m | 8px 16px |
Text
|
$mds-space-inset-stretch-l | 12px 24px |
Text
|
Use the stack concept to apply bottom margin consistently to separate block-level, 100%-wide items, arranged vertically.
Apply stack
constants to a component or element's margins.
Variable Name | Value | Result |
---|---|---|
$mds-space-stack-s | 0 0 6px |
A
B
C
|
$mds-space-stack-m | 0 0 8px |
A
B
C
|
$mds-space-stack-l | 0 0 12px |
A
B
C
|
$mds-space-stack-xl | 0 0 16px |
A
B
C
|
:last-child
component or element item in a set.Avoid indenting each item from the left and right when stacking components. Instead, apply inset padding to the container of the stacked items.
In the following example, two list-group
groups are stacked, and the space surrounding both applies an inset
to a container.
<div class="mds-container--dark mds-doc-space__inset-stack-container">
<ul class="mds-list-group">
<li class="mds-list-group__item mds-list-group__item--header"> First List </li>
<li class="mds-list-group__item ">
<a href="#" class="mds-list-group__link">
<span class="mds-list-group__item-label"> Item 1 </span>
</a>
</li>
<li class="mds-list-group__item ">
<a href="#" class="mds-list-group__link">
<span class="mds-list-group__item-label"> Item 2 </span>
</a>
</li>
</ul>
<ul class="mds-list-group">
<li class="mds-list-group__item mds-list-group__item--header"> Second List </li>
<li class="mds-list-group__item ">
<a href="#" class="mds-list-group__link">
<span class="mds-list-group__item-label"> Item 1 </span>
</a>
</li>
<li class="mds-list-group__item ">
<a href="#" class="mds-list-group__link">
<span class="mds-list-group__item-label"> Item 2 </span>
</a>
</li>
</ul>
</div>
.mds-doc-space__inset-stack-container {
padding: $mds-space-inset-m;
.mds-list-group {
margin: $mds-space-stack-m;
}
}
Use inline-left
spacing to separate inline elements flowing together from the left edge. This applies right margin to each item. The opposite is true for inline-right
.
inline-left
constants to a component or element's margins.:last-child
component or element item in a set.stack
and inline
concepts when inline items wrap.Variable Name | Value | Result |
---|---|---|
$mds-space-inline-left-s | 0 6px 0 0 | ABC |
$mds-space-inline-left-m | 0 8px 0 0 | ABC |
$mds-space-inline-left-l | 0 12px 0 0 | ABC |
$mds-space-inline-right-s | 0 0 0 6px | ABC |
$mds-space-inline-right-m | 0 0 0 8px | ABC |
$mds-space-inline-right-l | 0 0 0 12px | ABC |
In order to unify spacing concepts across the library, the System crops out the unpredictable impact of line-height
at the top and bottom of text blocks.
This effect is achieved by the mds-text-crop()
mixin available within the src/library/styles/shared/typography.scss
file, which trims the margin-top
and margin-bottom
of an element using :before
and :after
pseudo elements.
The mds-text-crop()
mixin is applied to a component or element block:
.mds-form__microcopy {
@include mds-text-crop();
...
}
Many System components are offered in two or more sizes, such as small, medium and large. Space is configured to adjust padding, margin and other concerns at each increment. These concepts enable multiple components to be positioned together vertically or horizontally with consistency regardless of size.
Many components use the incremental-spacing()
mixin within the src/library/styles/size.scss
file. This macro enables an engineer to quickly apply System spacing concepts across component elements.
Parameter | Default | Examples | Outcome |
---|---|---|---|
|
None |
|
Includes component name within selectors. |
|
None |
|
Applies the spacing concept for use on margins or padding. |
|
|
|
Sets the “middle” size so that spacing is properly encoded across levels. |
|
|
|
Applies spacing at the block- or element-level selectors, consistent with BEM methodology. |
|
false |
|
Accepts a SASS list of CSS properties that the space value will be applied to. If not provided, the mixin will select the CSS property based on the $spacing-type. |
|
0 |
|
Used in conjunction with $property-list. A positive or negative px value that is added to the values. Output by the mixin. Used only in special cases to correct alignment issues. |
|
|
If set to false, the incremental-spacing mixin will recreate the same effect as the |
For example, the System textbox Form element applies space as:
.mds-form__input {
@include incremental-spacing( 'form__input',
'inset',
$selector-level: 'block',
$text-cropped: false);
}
Similarly, the subsection item variant of the List Group component applies space as:
.mds-list-group__item--sublist {
@include incremental-spacing( 'list-group',
'default',
$property-list: ('padding-left'),
$space-adjustment: 2px);
}