A best-practices CSS foundation
CSS
Clone or download
Permalink
Failed to load latest commit information.
.editorconfig 6.0.0 Jun 24, 2018
.gitignore 6.0.0 Jun 24, 2018
.travis.yml 6.0.0 Jun 24, 2018
CHANGELOG.md 6.0.0 Jun 24, 2018
CONTRIBUTING.md 6.0.0 Jun 24, 2018
LICENSE.md 6.0.0 Jun 24, 2018
README.md add ~ to CSS import Jul 26, 2018
package.json 6.0.0 Jun 24, 2018
sanitize.css Remove duplication in comment Aug 7, 2018

README.md

sanitize.css sanitize

sanitize.css is a CSS library that provides consistent, cross-browser default styling of HTML elements alongside useful defaults.

How to get it

NPM

npm install --save sanitize.css

Download

See https://csstools.github.io/sanitize.css/latest/sanitize.css

CDN

see https://cdnjs.com/libraries/10up-sanitize.css

How to use it (NPM + WebPack)

Import the package

in CSS (or LESS/SCSS/Stylus)

@import '~sanitize.css';

or in javascript:

import 'sanitize.css';

minimally required webpack.config.js:

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [ 'style-loader', 'css-loader' ]
      }
    ]
  }
}

What does it do?

  • Normalizes styles for a wide range of elements.
  • Corrects bugs and common browser inconsistencies.
  • Provides common, useful defaults.
  • Explains what code does using detailed comments.

Features

Box sizing defaults to border-box
*, ::before, ::after {
  box-sizing: border-box;
}
Backgrounds do not repeat by default
*, ::before, ::after {
  background-repeat: no-repeat;
}
Pseudo-elements inherit text decoration and vertical alignment
::before,
::after {
  text-decoration: inherit;
  vertical-align: inherit;
}
Cursors only change to hint non-obvious interfaces
html {
  cursor: default;
}
Words break to prevent prevent overflow
html {
  word-break: break-all;
}
Documents do not use a margin for outer padding
body {
  margin: 0;
}
Navigation lists do not include a marker style
nav ol, nav ul {
  list-style: none;
}
Text selections do not include text shadows
::selection {
  background-color: #b3d4fc;
  color: #000;
  text-shadow: none;
}
Media elements align to the text center of other content
audio, canvas, iframe, img, svg, video {
  vertical-align: middle;
}
SVGs fallback to the current text color
svg {
  fill: currentColor;
}
Tables do not include additional border spacing
table {
  border-collapse: collapse;
}
Form controls are easily style-able
button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}
Textareas only resize vertically by default
textarea {
  resize: vertical;
}
Single taps are dispatched immediately on clickable elements
a, area, button, input, label, select, summary, textarea, [tabindex] {
  -ms-touch-action: manipulation;
  touch-action: manipulation;
}
ARIA roles include visual cursor hints
[aria-busy="true"] {
  cursor: progress;
}

[aria-controls] {
  cursor: pointer;
}

[aria-disabled] {
  cursor: default;
}
Visually hidden content remains accessible
[aria-hidden="false"][hidden]:not(:focus) {
  clip: rect(0, 0, 0, 0);
  display: inherit;
  position: absolute;
}

Differences

normalize.css and sanitize.css correct browser bugs while carefully testing and documenting changes. normalize.css styles adhere to css specifications. sanitize.css styles adhere to common developer expectations and preferences. reset.css unstyles all elements. Both sanitize.css and normalize.css are maintained in sync.

Browser support

  • Chrome (last 3)
  • Edge (last 3)
  • Firefox (last 3)
  • Firefox ESR
  • Opera (last 3)
  • Safari (last 3)
  • iOS Safari (last 2)
  • Internet Explorer 9+

Contributing

Please read the contribution guidelines in order to make the contribution process easy and effective for everyone involved.

Similar Projects

Acknowledgements

sanitize.css is a project by Jonathan Neal, built upon normalize.css, a project by Jonathan Neal, co-created with Nicolas Gallagher.