๐
backpack.css A lightweight and somewhat opinionated CSS foundation that is best suited to applications.
Table of contents
- Installation
- How to use
- Bundle size
- Motivation
- What it does
- Evolution
- Browser support
- Contributing
- Versioning
- Credits
- License
Installation
npm
Run the following command using npm:
npm install backpack.css --save-dev
If you prefer Yarn, use this command instead:
yarn add backpack.css --dev
Download
CDN
How to use
backpack.css is pretty easy to use. The one strict rule is that it must come before your project's CSS to ensure correct ordering of your styles and to be able to override any of backpack.css styles.
With a bundler (webpack)
JS
import 'backpack.css';
import '[path(s)-to-your-project-css]';
CSS
If you're using webpack, then use the tilde (~
) prefix at the start of the path, e.g.:
@import '~backpack.css';
@import '[path(s)-to-your-project-css]';
No bundler
Link to backpack.css using a <link>
element in your HTML Head, e.g.:
<head>
[โฆ]
<link rel="stylesheet" href="https://unpkg.com/backpack.css" />
<link rel="stylesheet" href="[path-to-your-project-css]" />
</head>
Overriding
backpack.css is just CSS so you can easily override any of its styles just as you would override any CSS, as in, via the rules of the cascade and specificity.
For example, if you don't want to use the global system font-stack defined in main-root.css
then override it in your project CSS like so:
html {
font-family: serif;
}
Bundle size
Motivation
Nowadays I'm building React applications that have highly componentised User Interfaces (UI) making use of native CSS layout mechanisms such as Flexbox and Grid. I'm no longer finding the need for heavy-handed CSS frameworks that handle most of my UI concerns, especially layout and utilities. Instead, I build components with a smidgen of global styles.
What I do need, however, are a bunch of smart and sensible foundational styles suited for applications that I would typically forget project to projectโthink Normalize.css and then some. Something lightweight, super easy to integrate, and can easily be overridden or allow for modular use, thus giving birth to backpack.css
What it does
- Applies sensible form element resets, normalisations, and fixes, e.g. remove all user-agent styles from buttons.
- Applies sensible interactive styles, e.g. avoid 300ms click delay on touch devices.
- Applies foundational print styles.
- Applies a system font, including monospace fonts.
- Applies the nicer
border-box
value for thebox-sizing
property to all elements. - Applies sensible OpenType features (see OpenType features below).
- Makes all images and videos responsive.
- Removes margins, paddings, and borders from all elements except
<input>
so that everything is on an even playing field. - Removes the bullets from lists.
- Removes all user-agent styles from heading elements and resets them to have the same styles as the body copy.
- Removes the "focus ring" for mouse users.
And moreโฆ
All of the CSS is very well documented if you want to dig deeper.
OpenType features
As mentioned above, backpack.css applies sensible OpenType features. However, due to the poor support of the font-variant-
properties, backpack.css has to declare their equivalents via the better supported, but harder to maintain, font-feature-settings
property (the font-feature-settings
properties should always come first).
Here are some resources on this:
- Utility OpenType
- Normalize-OpenType.css
- Syntax for OpenType features in CSS
- Caring about OpenType features
- OpenType features in CSS
Evolution
backpack.css is the third CSS framework/library I've created. Looking at each one lets you see how UI development has evolved over the years with each iteration getting smaller and smaller.
- Scally circa 2014
- Shell circa 2016
- backpack.css circa 2018
Browser support
Here is the Browserslist query backpack.css uses:
last 4 versions and > 0.5%,
Firefox ESR,
not ie < 11,
not op_mini all,
not dead
Which you can see here.
Browserslist is used for Autoprefixer. Autoprefixer only adds a tiny amount of vendor prefixes, the main properties being prefixed are:
font-feature-settings
font-variant-ligatures
This doesn't mean that backpack.css cannot be used in browsers outside of the above Browserslist query, just that compatibility is ensured with the ones within the query.
Contributing
Please see our contributing guidelines.
Versioning
backpack.css is maintained under the Semantic Versioning guidelines. We'll do our best to adhere to those guidelines and strive to maintain backwards compatibility.
See the change log.
Credits
And anyone else who's been so kind to share their work out in the open.
License
The code is available under the MIT license.