Convert Figma logo to code with AI

csstools logosanitize.css

A best-practices CSS foundation

5,204
314
5,204
20

Top Related Projects

A modern alternative to CSS resets

A tiny modern CSS reset

🐒 Normalize browsers' default style

A drop-in collection of CSS styles to make simple websites just a little nicer

4,104

:cherry_blossom: a minimal css framework/theme.

4,952

MVP.css — Minimalist classless CSS stylesheet for HTML elements

Quick Overview

Sanitize.css is a CSS library that provides consistent, cross-browser default styling of HTML elements. It's designed to be a modern alternative to traditional CSS resets, offering a more opinionated approach to normalizing styles across different browsers and devices.

Pros

  • Provides a solid foundation for consistent styling across browsers
  • Regularly updated to support modern browsers and CSS features
  • Lightweight and modular, allowing developers to use only what they need
  • Well-documented and easy to integrate into existing projects

Cons

  • May require overriding some styles for specific design needs
  • Opinionated approach might not suit all project requirements
  • Learning curve for developers accustomed to traditional CSS resets
  • Limited customization options out of the box

Code Examples

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

This code imports the sanitize.css library from a CDN, applying its styles to your HTML document.

  1. Importing in a CSS file:
@import 'sanitize.css';

/* Your custom styles here */

This example shows how to import sanitize.css in your own CSS file, allowing you to add custom styles afterward.

  1. Using with a CSS preprocessor (e.g., Sass):
@import 'sanitize.css/sanitize';
@import 'sanitize.css/assets';
@import 'sanitize.css/forms';
@import 'sanitize.css/typography';

// Your custom styles here

This code demonstrates importing specific modules from sanitize.css when using a CSS preprocessor like Sass.

Getting Started

To use sanitize.css in your project, follow these steps:

  1. Install via npm:

    npm install sanitize.css
    
  2. Import in your main CSS file or HTML:

    @import 'sanitize.css';
    

    or

    <link href="path/to/sanitize.css" rel="stylesheet" />
    
  3. (Optional) Import additional modules as needed:

    @import 'sanitize.css/forms.css';
    @import 'sanitize.css/typography.css';
    
  4. Add your custom styles after the sanitize.css import to ensure they take precedence.

Competitor Comparisons

A modern alternative to CSS resets

Pros of normalize.css

  • Lighter weight and smaller file size
  • More widely adopted and battle-tested in production environments
  • Focuses on normalizing styles across browsers without opinionated defaults

Cons of normalize.css

  • Less comprehensive coverage of modern CSS features and properties
  • Doesn't address some accessibility concerns that sanitize.css tackles
  • May require additional resets or customizations for a fully consistent baseline

Code Comparison

normalize.css:

html {
  line-height: 1.15;
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
}

sanitize.css:

*, ::before, ::after {
  box-sizing: border-box;
}
html {
  cursor: default;
  line-height: 1.5;
  -moz-tab-size: 4;
  tab-size: 4;
  -webkit-tap-highlight-color: transparent;
}

Both projects aim to provide a consistent starting point for CSS across different browsers. normalize.css focuses on preserving useful browser defaults while correcting common bugs, while sanitize.css takes a more opinionated approach by providing additional resets and addressing modern CSS features.

normalize.css is more lightweight and widely adopted, making it a popular choice for projects that need a simple normalization solution. However, sanitize.css offers more comprehensive coverage of modern CSS properties and addresses some accessibility concerns that normalize.css doesn't tackle.

The code comparison shows that sanitize.css includes more aggressive resets and modern property adjustments, while normalize.css takes a more minimal approach to browser normalization.

A tiny modern CSS reset

Pros of minireset.css

  • Extremely lightweight (only about 0.5KB)
  • Focuses solely on resetting default styles, making it easier to build upon
  • Simple and straightforward, with minimal complexity

Cons of minireset.css

  • Less comprehensive than sanitize.css, potentially requiring additional resets
  • Doesn't address cross-browser consistency issues as thoroughly
  • Lacks some modern CSS features and optimizations present in sanitize.css

Code Comparison

minireset.css:

html,
body,
p,
ol,
ul,
li,
dl,
dt,
dd,
blockquote,
figure,
fieldset,
legend,
textarea,
pre,
iframe,
hr,
h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0;
  padding: 0;
}

sanitize.css:

*,
::before,
::after {
  box-sizing: border-box;
}

html {
  cursor: default;
  line-height: 1.5;
  -moz-tab-size: 4;
  tab-size: 4;
  -webkit-tap-highlight-color: transparent;
  -ms-text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
  word-break: break-word;
}

The code comparison shows that minireset.css focuses on resetting margins and paddings for specific elements, while sanitize.css takes a more comprehensive approach, addressing box-sizing, cursor behavior, and text adjustments for better cross-browser consistency.

🐒 Normalize browsers' default style

Pros of modern-normalize

  • Smaller file size, making it more lightweight and faster to load
  • Focuses on modern browsers, allowing for more streamlined and efficient code
  • Regularly updated to keep pace with evolving browser standards

Cons of modern-normalize

  • Less comprehensive than sanitize.css, potentially requiring additional customization
  • May not provide sufficient normalization for older browsers or complex projects
  • Lacks some advanced features present in sanitize.css, such as form element normalization

Code Comparison

modern-normalize:

*, ::before, ::after {
  box-sizing: border-box;
}

html {
  line-height: 1.15;
  -webkit-text-size-adjust: 100%;
}

sanitize.css:

*, ::before, ::after {
  box-sizing: border-box;
}

html {
  line-height: 1.15;
  -webkit-text-size-adjust: 100%;
  -moz-tab-size: 4;
  tab-size: 4;
}

Both projects aim to provide a consistent starting point for CSS styling across browsers. modern-normalize is more focused on modern browsers and offers a lighter approach, while sanitize.css provides a more comprehensive solution with additional features and broader browser support. The choice between the two depends on project requirements, target browsers, and desired level of customization.

A drop-in collection of CSS styles to make simple websites just a little nicer

Pros of Water.css

  • Provides a complete, opinionated design out of the box
  • Lightweight and easy to implement with a single CSS file
  • Includes dark mode support

Cons of Water.css

  • Less flexible for custom designs due to its opinionated nature
  • May require overriding styles for specific use cases
  • Smaller community and fewer updates compared to Sanitize.css

Code Comparison

Sanitize.css focuses on normalizing styles:

*, ::before, ::after {
  box-sizing: border-box;
}

html {
  line-height: 1.15;
}

Water.css provides complete styling:

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  line-height: 1.4;
  max-width: 800px;
  margin: 20px auto;
  padding: 0 10px;
  color: #363636;
  background: #ffffff;
}

Summary

Sanitize.css is a CSS normalization library that provides a consistent foundation for building custom styles. It focuses on correcting browser inconsistencies and improving default styles.

Water.css, on the other hand, is a complete CSS framework that offers a ready-to-use design with minimal effort. It's ideal for quickly styling simple websites or prototypes but may be less suitable for projects requiring extensive customization.

Choose Sanitize.css for a clean slate to build upon, or Water.css for rapid development with a pre-designed look.

4,104

:cherry_blossom: a minimal css framework/theme.

Pros of Sakura

  • Provides a complete, opinionated design out of the box
  • Lightweight and minimal, with a focus on readability
  • Includes a dark mode option

Cons of Sakura

  • Less flexible for custom designs compared to Sanitize.css
  • May require more overrides for specific project needs
  • Smaller community and fewer updates

Code Comparison

Sakura:

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  line-height: 1.8;
  max-width: 38em;
  margin: auto;
  color: #4a4a4a;
  background-color: #f9f9f9;
  padding: 13px;
}

Sanitize.css:

*,
::before,
::after {
  box-sizing: border-box;
}

html {
  cursor: default;
  line-height: 1.5;
  -moz-tab-size: 4;
  tab-size: 4;
  -webkit-tap-highlight-color: transparent;
  -ms-text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
  word-break: break-word;
}

Sakura provides a more complete styling solution with specific design choices, while Sanitize.css focuses on normalizing browser styles and providing a consistent base. Sakura is better suited for quick, attractive layouts, while Sanitize.css offers more flexibility for custom designs.

4,952

MVP.css — Minimalist classless CSS stylesheet for HTML elements

Pros of MVP

  • Provides a complete, opinionated CSS framework with pre-styled components
  • Offers a more visually appealing default design out of the box
  • Includes responsive design features and mobile-friendly layouts

Cons of MVP

  • Less flexible and customizable compared to Sanitize.css
  • Larger file size due to additional styling and components
  • May require overriding styles for projects with specific design requirements

Code Comparison

MVP:

:root {
    --border-radius: 5px;
    --box-shadow: 2px 2px 10px;
    --color: #118bee;
    --color-accent: #118bee15;
    --color-bg: #fff;
    --color-bg-secondary: #e9e9e9;
    --color-secondary: #920de9;
    --color-secondary-accent: #920de90b;
    --color-shadow: #f4f4f4;
    --color-text: #000;
    --color-text-secondary: #999;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    --hover-brightness: 1.2;
    --justify-important: center;
    --justify-normal: left;
    --line-height: 1.5;
    --width-card: 285px;
    --width-card-medium: 460px;
    --width-card-wide: 800px;
    --width-content: 1080px;
}

Sanitize.css:

*, ::before, ::after {
  box-sizing: border-box;
}

html {
  cursor: default;
  line-height: 1.5;
  -moz-tab-size: 4;
  tab-size: 4;
  -webkit-tap-highlight-color: transparent;
  -ms-text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
  word-break: break-word;
}

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

sanitize.css sanitize

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().

Usage

<link href="https://cdn.skypack.dev/sanitize.css" rel="stylesheet" />

Learn more about sanitize.css.

Forms CSS

A separate stylesheet that normalizes form controls without side effects.

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

Learn more about forms.css.

Assets CSS

A separate stylesheet that applies a comfortable measure to plain documents.

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

Learn more about assets.css.

Typography CSS

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.

Reduce Motion 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.

System-UI

A separate stylesheet that adds support for using system-ui in Firefox.

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

UI-Monospace

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" />

Install

npm install sanitize.css --save

Webpack Usage

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

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.

Browser support

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

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.

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

Forms

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" />

Forms Features

Form controls appear visually consistent and restyle consistently
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;
}
Expandable select controls appear visually consistent
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;
}
Placeholders appear visually consistent in Internet Explorer
:-ms-input-placeholder {
  color: rgba(0, 0, 0, 0.54);
}

Assets

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" />

Assets Features

Assets use a comfortable measure in all browsers
iframe,
img,
input,
select,
textarea {
  height: auto;
  max-width: 100%;
}

Typography

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" />

Typography Features

Typography uses the default system 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 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;
}

Reduce Motion

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" />

Reduce Motion Features

Animations, scrolling effects, and transitions are reduced in all browsers
@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;
  }
}

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.

NPM DownloadsLast 30 Days