Socket
Socket
Sign inDemoInstall

sanitize.css

Package Overview
Dependencies
0
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    sanitize.css

A best-practices CSS foundation


Version published
Maintainers
1
Install size
33.6 kB
Created

Package description

What is sanitize.css?

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.

What are sanitize.css's main functionalities?

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; }

Other packages similar to sanitize.css

Changelog

Source

10.0.0 (June 3, 2019)

  • Added: Opinionated page measure via page.css.
  • Added: Opinionated border normalization on form controls to match UA.
  • Added: Opinionated font and letter-spacing as inherit on form controls.
  • Added: Opinionated normalization of select controls.
  • Added: Opinionated normalization of placeholders in Internet Explorer.
  • Added: Opinionated border removal on iframes in all browsers.
  • Removed: Opinionated border-radius on form controls.
  • Removed: Opinionated box-shadow on form controls to match UA expectations.
  • Fixed: Edge comments without Chrome are are changed to Edge 18-.
  • Fixed: Chrome comments without Edge have Edge added.
  • Fixed: Nested list dl normalizations split.
  • Fixed: Logical margin-block normalization changed to margin.
  • Fixed: Used consistent quotes around typefaces in typography.css.

These fixes were brought in from normalize.css v10.1.0.

Readme

Source

sanitize.css sanitize

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

It is developed alongside normalize.css, which means every normalization is included, and every normalization and opinion are clearly marked and documented.

Usage

<link href="https://unpkg.com/sanitize.css" rel="stylesheet" />

Forms

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 sizes form controls without affecting native styles.

<link href="https://unpkg.com/sanitize.css/formsize.css" rel="stylesheet" />

Typography

A separate stylesheet that normalizes typography using system interface fonts.

<link href="https://unpkg.com/sanitize.css/typography.css" rel="stylesheet" />

Measure

A separate stylesheet that applies a comfortable measure to the page.

<link href="https://unpkg.com/sanitize.css/measure.css" rel="stylesheet" />

Install

npm install --save sanitize.css
Webpack Usage

Import sanitize.css in CSS:

@import 'sanitize.css';
@import 'sanitize.css/typography.css';
@import 'sanitize.css/forms.css';

Alternatively, import sanitize.css in JS:

import 'sanitize.css';
import 'sanitize.css/typography.css';
import 'sanitize.css/forms.css';

In webpack.config.js, be sure to use the appropriate loaders:

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;
}
Text has a comfortable line height in all browsers
html {
  line-height: 1.5;
}
Tabs appear the same on the web as in a typical editor
html {
  tab-size: 4;
}
Words break to 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;
  padding: 0;
}
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:not([fill]) {
  fill: currentColor;
}
Tables do not include additional border spacing
table {
  border-collapse: collapse;
}
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="true"], [disabled] {
  cursor: default;
}
Visually hidden content remains accessible
[aria-hidden="false"][hidden] {
  display: initial;
}

[aria-hidden="false"][hidden]:not(:focus) {
  clip: rect(0, 0, 0, 0);
  position: absolute;
}

Typography

sanitize.css includes a separate stylesheet for normalizing typography using system interface fonts.

Forms

sanitize.css includes a separate stylesheet for normalizing forms using minimal, standards-like styling.

Browser

<link href="https://unpkg.com/sanitize.css/typography.css" rel="stylesheet" />

Download

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

CDN

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

Typography Features
The default font is the system ui font
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";
}
Pre-formatted and code-formatted text uses the monospace system ui font
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;
}

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.

Acknowledgements

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

Keywords

FAQs

Last updated on 03 Jun 2019

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc