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.
Fund Name
|
Ticker
|
---|---|
Dodge & Cox Income | DODIX |
Western Asset Core Plus Bond I | WACPX |
Vanguard GNMA Inc | VFIIX |
Apply inset
constants to component and element padding, like an item in a List Group or a cell in a Data Table.
Constant Name
|
Value
|
Result
|
---|---|---|
$mds-space-inset-quarter-x | 2px |
Text
|
$mds-space-inset-half-x | 4px |
Text
|
$mds-space-inset-three-quarter-x | 6px |
Text
|
$mds-space-inset-1-x | 8px |
Text
|
$mds-space-inset-1-and-a-half-x | 12px |
Text
|
$mds-space-inset-2-x | 16px |
Text
|
$mds-space-inset-3-x | 24px |
Text
|
$mds-space-inset-4-x | 32px |
Text
|
$mds-space-inset-8-x | 64px |
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-gray;
color: $mds-text-color-primary-on-dark;
padding: $mds-space-inset-1-x;
}
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.
Constant 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.
Constant Name
|
Value
|
Result
|
---|---|---|
$mds-space-stack-quarter-x | 0 0 2px |
A
B
C
|
$mds-space-stack-half-x | 0 0 4px |
A
B
C
|
$mds-space-stack-three-quarter-x | 0 0 6px |
A
B
C
|
$mds-space-stack-1-x | 0 0 8px |
A
B
C
|
$mds-space-stack-1-and-a-half-x | 0 0 12px |
A
B
C
|
$mds-space-stack-2-x | 0 0 16px |
A
B
C
|
$mds-space-stack-3-x | 0 0 24px |
A
B
C
|
$mds-space-stack-4-x | 0 0 32px |
A
B
C
|
$mds-space-stack-8-x | 0 0 64px |
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-gray 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-text">
Item 1
</span>
</a>
</li>
<li class="mds-list-group__item ">
<a href="#" class="mds-list-group__link">
<span class="mds-list-group__item-text">
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-text">
Item 1
</span>
</a>
</li>
<li class="mds-list-group__item ">
<a href="#" class="mds-list-group__link">
<span class="mds-list-group__item-text">
Item 2
</span>
</a>
</li>
</ul>
</div>
.mds-doc-space__inset-stack-container {
padding: $mds-space-inset-1-x;
.mds-list-group {
margin: $mds-space-stack-1-x;
}
}
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
and inline-right
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.
Constant Name
|
Value
|
Result
|
---|---|---|
$mds-space-inline-left-half-x | 0 4px 0 0 |
A
B
C
|
$mds-space-inline-left-three-quarter-x | 0 6px 0 0 |
A
B
C
|
$mds-space-inline-left-1-x | 0 8px 0 0 |
A
B
C
|
$mds-space-inline-left-1-and-a-half-x | 0 12px 0 0 |
A
B
C
|
$mds-space-inline-left-2-x | 0 16px 0 0 |
A
B
C
|
$mds-space-inline-right-half-x | 0 0 0 4px |
A
B
C
|
$mds-space-inline-right-three-quarter-x | 0 0 0 6px |
A
B
C
|
$mds-space-inline-right-1-x | 0 0 0 8px |
A
B
C
|
$mds-space-inline-right-1-and-a-half-x | 0 0 0 12px |
A
B
C
|
$mds-space-inline-right-2-x | 0 0 0 16px |
A
B
C
|
Use generic spacing constants when creating spaces which don’t relate to any of the existing concepts documented above.
Constant Name
|
Value
|
---|---|
$mds-space-quarter-x | 2px |
$mds-space-half-x | 4px |
$mds-space-three-quarter-x | 6px |
$mds-space-1-x | 8px |
$mds-space-1-and-a-half-x | 12px |
$mds-space-2-x | 16px |
$mds-space-2-and-a-half-x | 20px |
$mds-space-3-x | 24px |
$mds-space-4-x | 32px |
$mds-space-5-x | 40px |
$mds-space-6-x | 48px |
$mds-space-7-x | 56px |
$mds-space-8-x | 64px |
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);
}