Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
sanitize.css
Advanced tools
Package description
The sanitize.css package is a CSS library that provides consistent, cross-browser default styling for HTML elements. It's designed to normalize styles across different browsers, remove default margins, and apply a consistent box-sizing model. This helps in creating a more predictable styling baseline for web projects.
Normalize styles
This code ensures that every element on the page, including pseudo-elements, inherits the box-sizing property from the html element, which is set to border-box. This makes it easier to manage layouts as it includes padding and border in the element's total width and height.
html { box-sizing: border-box; } *, *::before, *::after { box-sizing: inherit; }
Remove default margins
This code removes the default margins from common elements like body, headings, paragraphs, and others. It provides a clean slate for adding custom spacing without having to override browser defaults.
body, h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd { margin: 0; }
Set default font-family
This sets the default font family to sans-serif for the entire HTML document, ensuring a consistent typography baseline across different browsers.
html { font-family: sans-serif; }
normalize.css is a popular CSS reset library that aims to normalize styles across browsers. It focuses on fixing common inconsistencies and preserving useful defaults rather than unifying all styles like sanitize.css. While both aim to provide a consistent styling baseline, normalize.css is more about correcting quirks without imposing a specific styling philosophy.
reset-css is another CSS reset library that aims to strip away all default browser styling on elements. Unlike sanitize.css, which applies minimalistic default styles and normalizes differences, reset-css provides a clean slate by removing all styles, allowing developers to start styling from scratch.
Changelog
13.0.0 (September 14, 2021)
:where
too all selectors, reducing specificity to nearly zero.background-repeat: no repeat
.select
selector.evergreen.css
, forms.evergreen.css
, and pages.css
.Readme
sanitize.css is a CSS library that provides consistent, cross-browser default styling of HTML elements alongside useful defaults.
sanitize.css is developed alongside normalize.css, which means every normalization is included, and every normalization and opinion are clearly marked and documented.
sanitize.css wraps styles in zero-specificity selectors using :where()
.
<link href="https://cdn.skypack.dev/sanitize.css" rel="stylesheet" />
Learn more about sanitize.css
.
A separate stylesheet that normalizes form controls without side effects.
<link href="https://unpkg.com/sanitize.css/forms.css" rel="stylesheet" />
A separate stylesheet that applies a comfortable measure to plain documents.
<link href="https://unpkg.com/sanitize.css/assets.css" rel="stylesheet" />
A separate stylesheet that normalizes typography using system interface fonts.
<link href="https://unpkg.com/sanitize.css/typography.css" rel="stylesheet" />
Learn more about typography.css
.
A separate stylesheet for restricting motion when the user has requested this at system level.
<link href="https://unpkg.com/sanitize.css/reduce-motion.css" rel="stylesheet" />
Learn more about reduce-motion.css
.
A separate stylesheet that adds support for using system-ui
in Firefox.
<link href="https://unpkg.com/sanitize.css/system-ui.css" rel="stylesheet" />
A separate stylesheet that adds support for using ui-monospace
in Chrome, Edge, and Firefox.
<link href="https://unpkg.com/sanitize.css/ui-monospace.css" rel="stylesheet" />
npm install sanitize.css --save
Import sanitize.css in CSS:
@import '~sanitize.css';
@import '~sanitize.css/forms.css';
@import '~sanitize.css/typography.css';
Alternatively, import sanitize.css in JS:
import 'sanitize.css';
import 'sanitize.css/forms.css';
import 'sanitize.css/typography.css';
In webpack.config.js
, be sure to use the appropriate loaders:
module.exports = {
module: {
rules: [
{
test: /\.css$/,
use: [ 'style-loader', 'css-loader' ]
}
]
}
}
Download
See https://csstools.github.io/sanitize.css/latest/sanitize.css
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.
*, ::before, ::after {
box-sizing: border-box;
}
*, ::before, ::after {
background-repeat: no-repeat;
}
::before,
::after {
text-decoration: inherit;
vertical-align: inherit;
}
html {
cursor: default;
}
html {
line-height: 1.5;
}
html {
tab-size: 4;
}
html {
word-break: break-all;
}
body {
margin: 0;
}
nav ol, nav ul {
list-style: none;
padding: 0;
}
audio, canvas, iframe, img, svg, video {
vertical-align: middle;
}
svg:not([fill]) {
fill: currentColor;
}
table {
border-collapse: collapse;
}
textarea {
resize: vertical;
}
a, area, button, input, label, select, summary, textarea, [tabindex] {
-ms-touch-action: manipulation;
touch-action: manipulation;
}
[aria-busy="true"] {
cursor: progress;
}
[aria-controls] {
cursor: pointer;
}
[aria-disabled="true"], [disabled] {
cursor: default;
}
[aria-hidden="false"][hidden] {
display: initial;
}
[aria-hidden="false"][hidden]:not(:focus) {
clip: rect(0, 0, 0, 0);
position: absolute;
}
sanitize.css includes a separate stylesheet for normalizing forms using minimal, standards-like styling.
<link href="https://unpkg.com/sanitize.css" rel="stylesheet" />
<link href="https://unpkg.com/sanitize.css/forms.css" rel="stylesheet" />
button, input, select, textarea {
background-color: transparent;
border: 1px solid WindowFrame;
color: inherit;
font: inherit;
letter-spacing: inherit;
padding: 0.25em 0.375em;
}
[type="color"],
[type="range"] {
border-width: 0;
padding: 0;
}
select {
-moz-appearance: none;
-webkit-appearance: none;
background: no-repeat right center / 1em;
border-radius: 0;
padding-right: 1em;
}
select:not([multiple]):not([size]) {
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='4'%3E%3Cpath d='M4 0h6L7 4'/%3E%3C/svg%3E");
}
::-ms-expand {
display: none;
}
:-ms-input-placeholder {
color: rgba(0, 0, 0, 0.54);
}
sanitize.css includes a separate stylesheet for normalizing restricting the size of assets in all browsers.
<link href="https://unpkg.com/sanitize.css" rel="stylesheet" />
<link href="https://unpkg.com/sanitize.css/assets.css" rel="stylesheet" />
iframe,
img,
input,
select,
textarea {
height: auto;
max-width: 100%;
}
sanitize.css includes a separate stylesheet for normalizing typography using system interface fonts.
<link href="https://unpkg.com/sanitize.css" rel="stylesheet" />
<link href="https://unpkg.com/sanitize.css/typography.css" rel="stylesheet" />
html {
font-family:
system-ui,
/* macOS 10.11-10.12 */ -apple-system,
/* Windows 6+ */ Segoe UI,
/* Android 4+ */ Roboto,
/* Ubuntu 10.10+ */ Ubuntu,
/* Gnome 3+ */ Cantarell,
/* KDE Plasma 5+ */ Noto Sans,
/* fallback */ sans-serif,
/* macOS emoji */ "Apple Color Emoji",
/* Windows emoji */ "Segoe UI Emoji",
/* Windows emoji */ "Segoe UI Symbol",
/* Linux emoji */ "Noto Color Emoji";
}
code, kbd, pre, samp {
font-family:
/* macOS 10.10+ */ Menlo,
/* Windows 6+ */ Consolas,
/* Android 4+ */ Roboto Mono,
/* Ubuntu 10.10+ */ Ubuntu Monospace,
/* KDE Plasma 5+ */ Noto Mono,
/* KDE Plasma 4+ */ Oxygen Mono,
/* Linux/OpenOffice fallback */ Liberation Mono,
/* fallback */ monospace;
}
sanitize.css includes a separate stylesheet for restricting motion when the user has requested this at a system level.
<link href="https://unpkg.com/sanitize.css" rel="stylesheet" />
<link href="https://unpkg.com/sanitize.css/reduce-motion.css" rel="stylesheet" />
@media (prefers-reduced-motion: reduce) {
*,
::before,
::after {
animation-delay: -1ms !important;
animation-duration: 1ms !important;
animation-iteration-count: 1 !important;
background-attachment: initial !important;
scroll-behavior: auto !important;
transition-delay: 0s !important;
transition-duration: 0s !important;
}
}
Please read the contribution guidelines in order to make the contribution process easy and effective for everyone involved.
sanitize.css is a project by Jonathan Neal, built upon normalize.css, a project by Jonathan Neal, co-created with Nicolas Gallagher.
FAQs
A best-practices CSS foundation
The npm package sanitize.css receives a total of 2,752,228 weekly downloads. As such, sanitize.css popularity was classified as popular.
We found that sanitize.css demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.