Utilities are single-purpose styles that provide the backbone for layout. Once these are set, they should be considered immutable and never change or be extended. Each utility is designed to do one thing well, while making its usage simple and obvious with short, humanized naming conventions.
Change typographic styles and defaults with these utilities.
Bold
Regular
Italic
Caps
Left align
Center
Right align
Justify Bacon ipsum dolor sit amet chuck prosciutto landjaeger ham hock filet mignon shoulder hamburger pig venison.
<p class="bold">Bold</p>
<p class="regular">Regular</p>
<p class="italic">Italic</p>
<p class="caps">Caps</p>
<p class="left-align">Left align</p>
<p class="center">Center</p>
<p class="right-align">Right align</p>
<p class="justify">Justify Bacon ipsum dolor sit amet chuck prosciutto landjaeger ham hock filet mignon shoulder hamburger pig venison.</p>
Change the default document flow with display, float, and other utilities.
.inline { display: inline }
.block { display: block }
.inline-block { display: inline-block }
.overflow-hidden { overflow: hidden }
.overflow-scroll { overflow: scroll }
.clearfix:before,
.clearfix:after {
content: " ";
display: table
}
.clearfix:after { clear: both }
.left { float: left }
.right { float: right }
.fit { max-width: 100% }
.half-width { width: 50% }
.full-width { width: 100% }
Create a media object using basic utilities.
Body Bacon ipsum dolor sit amet chuck prosciutto landjaeger ham hock filet mignon shoulder hamburger pig venison.
<div class="clearfix mb2 outline-blue">
<div class="left p2 mr1">Image</div>
<div class="overflow-hidden">
<p><b>Body</b> Bacon ipsum dolor sit amet chuck prosciutto landjaeger ham hock filet mignon shoulder hamburger pig venison.</p>
</div>
</div>
For a container with a flexible center, use a double-sided media object.
Body Bacon ipsum dolor sit amet chuck prosciutto landjaeger ham hock filet mignon shoulder hamburger pig venison.
<div class="clearfix mb2 outline-blue">
<div class="left p2 mr1">Image</div>
<div class="right p2 ml1">Image</div>
<div class="overflow-hidden">
<p><b>Body</b> Bacon ipsum dolor sit amet chuck prosciutto landjaeger ham hock filet mignon shoulder hamburger pig venison.</p>
</div>
</div>
Margin and padding utilities are based on a global white space scale defined with variables. These utilities use a shorthand naming convention.
Shorthand | Description |
---|---|
m | Margin |
p | Padding |
t | Top |
r | Right |
b | Bottom |
l | Left |
x | X-axis (left and right) |
y | Y-axis (top and bottom) |
n | Negative (margin only) |
1 | --space-1 (default .5rem) |
2 | --space-2 (default 1rem) |
3 | --space-3 (default 2rem) |
4 | --space-4 (default 4rem) |
Change or reset default margins using the global white space scale. Negative x-axis margins are used to offset padding. Margin auto is used to horizontally center block-level elements with a set width.
.m0 { margin: 0 }
.mt0 { margin-top: 0 }
.mr0 { margin-right: 0 }
.mb0 { margin-bottom: 0 }
.ml0 { margin-left: 0 }
.m1 { margin: var(--space-1) }
.mt1 { margin-top: var(--space-1) }
.mr1 { margin-right: var(--space-1) }
.mb1 { margin-bottom: var(--space-1) }
.ml1 { margin-left: var(--space-1) }
.m2 { margin: var(--space-2) }
.mt2 { margin-top: var(--space-2) }
.mr2 { margin-right: var(--space-2) }
.mb2 { margin-bottom: var(--space-2) }
.ml2 { margin-left: var(--space-2) }
.m3 { margin: var(--space-3) }
.mt3 { margin-top: var(--space-3) }
.mr3 { margin-right: var(--space-3) }
.mb3 { margin-bottom: var(--space-3) }
.ml3 { margin-left: var(--space-3) }
.m4 { margin: var(--space-4) }
.mt4 { margin-top: var(--space-4) }
.mr4 { margin-right: var(--space-4) }
.mb4 { margin-bottom: var(--space-4) }
.ml4 { margin-left: var(--space-4) }
.mxn1 { margin-left: -var(--space-1); margin-right: -var(--space-1); }
.mxn2 { margin-left: -var(--space-2); margin-right: -var(--space-2); }
.mxn3 { margin-left: -var(--space-3); margin-right: -var(--space-3); }
.mxn4 { margin-left: -var(--space-4); margin-right: -var(--space-4); }
.mx-auto { margin-left: auto; margin-right: auto; }
Padding utilities are only available in symmetrical orientations. This is to normalize the spacing used around elements.
.p1 { padding: var(--space-1) }
.py1 { padding-top: var(--space-1); padding-bottom: var(--space-1) }
.px1 { padding-left: var(--space-1); padding-right: var(--space-1) }
.p2 { padding: var(--space-2) }
.py2 { padding-top: var(--space-2); padding-bottom: var(--space-2) }
.px2 { padding-left: var(--space-2); padding-right: var(--space-2) }
.p3 { padding: var(--space-3) }
.py3 { padding-top: var(--space-3); padding-bottom: var(--space-3) }
.px3 { padding-left: var(--space-3); padding-right: var(--space-3) }
.p4 { padding: var(--space-4) }
.py4 { padding-top: var(--space-4); padding-bottom: var(--space-4) }
.px4 { padding-left: var(--space-4); padding-right: var(--space-4) }
Margins and padding should never be declared outside of these utilities. This is meant to help create consistent rhythm and avoid magic numbers. If, for some reason, the default white space scale does not accomodate your design, customize and extend it before implementation.
These styles allow for conditionally showing and hiding elements using a mobile-first approach.
Prefix | Description |
---|---|
(no prefix) | Not scoped to a breakpoint |
sm- | --breakpoint-sm (default: min-width 40em) |
md- | --breakpoint-md (default: min-width 52em) |
lg- | --breakpoint-lg (default: min-width 64em) |
To adjust the default breakpoints, declare custom media queries after importing the file via Rework, or manually adjust them in CSS.
.sm-show, .md-show, .lg-show {
display: none !important
}
@media (--breakpoint-sm) {
.sm-show { display: block !important }
}
@media (--breakpoint-md) {
.md-show { display: block !important }
}
@media (--breakpoint-lg) {
.lg-show { display: block !important }
}
.hide { display: none !important }
@media (--breakpoint-sm) {
.sm-hide { display: none !important }
}
@media (--breakpoint-md) {
.md-hide { display: none !important }
}
@media (--breakpoint-lg) {
.lg-hide { display: none !important }
}
Resize the browser window to see the effect.
--breakpoint-sm
and up.--breakpoint-sm
and up.<h3 class="hide sm-show">Visible from <code>--breakpoint-sm</code> and up.</h3>
<h3 class="sm-hide red">Hidden from <code>--breakpoint-sm</code> and up.</h3>
Control wrapping at different screen widths.
<h1>
Responsive Line Break
<br class="md-show">
To Control Wrapping
</h1>
These styles alter the default document flow.
Use positions with caution. They are often unnecessary and commonly misused.
See the Guide to Basics for more info.
.relative { position: relative }
.absolute { position: absolute }
.fixed { position: fixed }
.top-0 { top: 0 }
.right-0 { right: 0 }
.bottom-0 { bottom: 0 }
.left-0 { left: 0 }
.z1 { z-index: 1 }
.z2 { z-index: 2 }
.z3 { z-index: 3 }
.z4 { z-index: 4 }
.absolute-center {
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
display: table;
}
Utility styles use the following variables. To alter these defaults, declare new values after importing Basscss with Rework.
:root {
--space-1: .5rem;
--space-2: 1rem;
--space-3: 2rem;
--space-4: 4rem;
--bold-font-weight: bold;
}
Utility styles are also available as a standalone NPM module.
npm install basscss-utilities