The New Simple and Lighter CSS Reset

Overview

The New CSS Reset

This new CSS reset is using the new CSS features:

  • The global CSS reset keywords, ‘unset’ and ‘revert’ keywords.
  • The new property of ‘all’ which can reset all properties combined.
  • The :where() pseudo-class to remove specificity.
  • The :not() pseudo-class with multi arguments.

What is the-new-css-reset resetting?

This CSS reset is built from the understanding that we don’t want to use default styles we are getting from the browsers, except the ‘display’ property.

This CSS reset removes all the default styles which we are getting on specific HTML elements except the ‘display’ property, as I already mentioned, and special HTML elements like iframe, canvas, img, svg, video, and audio.

In case you want the default style of the browser of a specific HTML element back, you can revert back to the default styles of the browser. For example:

input[type="checkbox"],
input[type="radio"] {
    all: revert;
}

or all input elements:

input,
textarea,
select {
   all: revert;
}

Download the Latest Version

NPM and How to Use?

The package name on NPM is 'the-new-css-reset'.

Import /css/reset.css before the regular styles of the project.

In a React project, insert it to the main entry file:

import "the-new-css-reset/css/reset.css"

Accessibility Recommendation

To keep your website accessibly, don't forget to take care of the :focus states.

:focus { /* focus styles */ }

/* or/and */

:focus-visible { /* keyboard only focus styles */ }

Browser Support

All evergreen browsers

  • Chrome, Edge: version 88+
  • FireFox: version 84+
  • Safari/iOS browsers: version 14+
  • Opera: version 75+
  • Samsung Browser: version 15+
Comments
  • Add summary to items not reset

    Add summary to items not reset

    This PR adds summary to the list of items not reset.

    The reason is that, by resetting it, the icon accompanying the summary in a details drop-down changes from an arrow, which usefully changes direction according to whether details is open or closed, to a bullet, which provides no such information and is essentially meaningless in this context anyway.

    This PR thus has the effect of retaining the arrow.

    opened by KTS915 9
  • Minimize use of revert

    Minimize use of revert

    Since the point is to eliminate browser inconsistencies by not using the browser's default styles, in principle it should be better to not use revert (whose value can differ depending on browser) unless needed. For instance,

    a, button {
        /* cursor: revert; */ 
        cursor: pointer;
    }
    
    opened by Justin-Marks 8
  • img should also have `height: auto;`

    img should also have `height: auto;`

    Considering the following common markup:

    <img src="image.jpg" width="800" height="600">
    

    Because of max-width: auto, the image will be squished when the viewport gets smaller than 800px.

    opened by cadars 8
  • Focus states & keyboard accessibility

    Focus states & keyboard accessibility

    First of all, thank you so much for building this! I've been trying it out in a few projects and it's honestly been a breath of fresh air to not have to constantly fight with default user agent styles to get things looking exactly the way I want.

    That said, I do have some concerns around accessibility of the reset in its default configuration, specifically because it removes the default browser focus outlines. This is the reset working as intended, but as it grows in popularity I fear that people who use it might not realize this and will build apps with really poor accessibility for keyboard users by not providing any custom focus styles on top of the reset.

    Some potential ideas to work around this:

    1. We can make an exception for the default focus styles and not override them. This way usages will continue to have a reasonable default level of accessibility for keyboard users.
    2. We can add a note in the readme, ideally very high up, mentioning that the reset removes focus styles, the consequences around that, and strongly recommend users to provide their own.

    I would personally vastly prefer 1 as a safer default, but 2 is probably better than nothing if we want to err on the purist side and override as much styling as possible. Definitely open to other ideas as well, and happy to send a PR once we settle on the approach!

    opened by lewisl9029 7
  • Firefox SVG sprite bug

    Firefox SVG sprite bug

    I noticed a strange bug in Firefox when using a SVG sprite. Some shapes render fine but others don't.

    CodeSandbox: https://codesandbox.io/s/reqrh Test Files: https://github.com/nicolaibach/svg-firefox-bug

    The bug goes away if symbol * is excluded explicitly:

    *:where(:not(iframe, canvas, img, svg, video):not(svg *, symbol *))

    opened by nicolaibach 7
  • Change `max-width` to `max-inline-size`

    Change `max-width` to `max-inline-size`

    Change max-width to max-inline-size in order to control layout through logical rather than physical, direction and dimension mappings. This helps with making websites internationally compatible. https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties

    opened by vicsantizo 4
  • TNCSSR + `-webkit-user-select: none` Breaks Text Input In Safari

    TNCSSR + `-webkit-user-select: none` Breaks Text Input In Safari

    When setting -webkit-user-select: none on the body, I can't type into text input fields in Safari, see here (code). Not sure what is happening exactly here (in Chrome everything works fine), but it seems related to TNCSSR. Feel free to delete if this is offtopic.

    opened by fweth 4
  • Problems with progress and draggable elements

    Problems with progress and draggable elements

    Hi,

    Your method render draggable true element not draggable and progress bar impossible to modify with css.

    Had to fix by modifying the first line like this for the moment: *:where(:not(iframe,canvas,img,svg,video,progress):not(svg *,symbol *)){all:unset;display:revert}

    I'm on Safari but the problems was tested with Firefox and Chrome too

    For Safari you have to revert -webkit-user-drag so let's assume you have to revert user-drag too. using [draggable=true] {-webkit-user-drag: element;} not sure on the user-drag usage at the moment (not tested on chrome and firefox and every element I want to be draggable are draggable="true" of course)

    sorry for my poor English.

    opened by vhanadium 4
  • Reset makes hr vanish

    Reset makes hr vanish

    Hello,

    all: unset resets all borders to zero, which makes <hr> tags disapear :

    Codepen : https://codepen.io/raphaelgoetter/pen/rNvmWwY?editors=1100

    opened by raphaelgoetter 3
  • Strange result with browsers on Windows

    Strange result with browsers on Windows

    I have a strange result with this reset: the <head> <title> tag and the content of <script> tags within the body are displayed as content in the browser.

    This happens only in browsers (tested in Chrome & Edge) on Windows.

    I debugged the issue and found out that the error is caused by

    *:where(:not(iframe, canvas, img, svg, video):not(svg *, symbol *)) {
      display: revert;
      all: unset;
    }
    
    opened by zero2one 3
  • Web component host reset

    Web component host reset

    I've been using this reset with web components (via LitElement). In doing so, I've found that the reset (both unset: all and display: revert) causes a lot of problems related to styling the :host (shadow root) selector.

    Problem

    Research suggests that the specificity for the :host selector is intended to make it act as the default style for a custom element. Therefore, it is expected to be overridden by any other styles.

    That places the shadow root in quite an awkward position following a reset. After all, the purpose of a reset is to strip browser styling. After that, any user-authored styling (including the defaults of custom elements) should be respected.

    Solution

    My solution is to add display: contents !important to the :host selector in each component. Then, if a custom root is desired, it can be implemented as a separate class, applied to a container element (like a div).

    /* Pass through root */
    :host {
    	display: contents !important;
    }
    
    /* Custom root */
    .container {
    	display: flex;
    }
    

    This solution is ideal in my case, because I don't like that shadow roots participate in the document layout in the first place; I prefer the pass-through behavior of React fragments (<></>).

    Related

    Related external links:

    opened by OhiraKyou 2
  • min-width has to be resetted to 0 for flexbox

    min-width has to be resetted to 0 for flexbox

    The "new" auto default value on min-width and max-width causes problems in Flexbox because flex-items do not shrink on small screens due to their content.

    auto computes to 0 for most elements... except for flex-items and grid-items.

    See: https://medium.com/the-crazy-coder/the-mystery-of-css-flex-layout-items-shrinking-8748145e96d9

    Since auto is now default value for min-width, it can't be just resetted to 0 with initial, unset nor revert. We need to explicitly set it to 0.

    See and try on Codepen: https://codepen.io/raphaelgoetter/pen/oLzzar?editors=1100

    opened by raphaelgoetter 4
  • Add text-size-adjust?

    Add text-size-adjust?

    Hello!

    I came across this article today on text-size-adjust and am wondering if it's worth setting it to none in the reset? Reading the MDN article, I'm not sure if unset does the same thing.

    opened by aaronsturm 0
  • Added test html file

    Added test html file

    Hey Elad, I really love your work! I published a css reset with similar goals a while back (https://www.npmjs.com/package/reset-css-complete) but I dig your approach so much more!

    Anyway, I thought I could share the simple html file I used for testing across browsers and thought that it might help you as well (for example, did you know that in chrome unsetting <input type="color"> is totally broken?)

    Hope you find this useful -Alex

    opened by alex-e-leon 5
  • Owner
    Elad Shechter
    I’m Elad Shechter, a Web Developer specializing in CSS & HTML design and architecture. Beside this, i’m the founder of CSS Masters Israel Community, Writer o
    Elad Shechter
    Easily open daily notes and periodic notes in new pane; customize periodic notes background; quick append new line to daily notes.

    Obsidian daily notes opener This plugin adds a command for opening daily notes in a new pane (so that a keyboard shortcut could be used!) and gives ex

    Xiao Meng 16 Dec 26, 2022
    :new:A new version of Icalingua.

    Icalingua 3 新版 Icalingua。将抛弃 Electron,转向网页前端 + Node 后端(类似于原来 icalingua-bridge-oicq)的模式。 正在开发中。当前技术栈选型: oicq2 socket.io Vue3 Fastify WindiCSS rxjs Mikr

    Icalingua++ 150 Dec 27, 2022
    Clinton Mbonu 20 Jun 30, 2022
    A library management system that built with JavaScript, HTML, and CSS. Allows the user to add new books and delete books.

    Awesome books: with ES6 in this project: Set up the linters for html, css, and JavaScript. Create a popup window for desktop and mobile. Built With Ht

    IBRAHIM AHMAT 7 Dec 18, 2022
    DripUI a collection of free Tailwind CSS components to bootstrap your new apps, projects or landing sites!

    DripUI - Tailwind Components DripUI is an amazing collection of free UI components to help you develop projects faster and easier. The most elegant co

    Dan 24 Nov 27, 2022
    Simple To-do list build using HTML5, CSS3, JavaScript and Webpack. You can add new tasks, remove and edit them.

    Simple To-do list build using HTML5, CSS3, JavaScript and Webpack. You can add new tasks, remove and edit them.

    Esteban Munoz 6 Mar 5, 2022
    This simple project aims to connect to an API to fetch score data and display it on a LeaderBoard box, as well as provide the tool to submit a new score.

    Leader Board: Hit the API! This simple project aims to connect to an API to fetch score data and display it on a LeaderBoard box, as well as provide t

    Andrés Felipe Arroyave Naranjo 12 Apr 6, 2022
    A simple JS To Do List bundled using Webpack. You can add new tasks, edit existing tasks, check completed tasks, and delete tasks from the list. It is built mainly with Javascript.

    To-Do-List A simple HTML list of To Do built using webpack and served by a webpack dev server. Live Link See Demo Built With HTML, CSS, Javascript To

    Michael Ugochukwu 3 May 10, 2022
    Simple NextJS Project Template to write less boilerplate code when starting a new Next JS Project

    Simple NextJS Project Template to write less boilerplate code when starting a new Next JS Project

    Juan David Ramirez Mendoza 1 Feb 12, 2022
    A simple CLI to patch the Fitbit OS Simulator with the new SSL certificate - March 2022

    patch-fitbit-simulator Only for Mac OS currently A simple CLI to patch the Fitbit OS Simulator certificate with the new SSL certificate for the Device

    Brandon Him 2 Mar 28, 2022
    A new, simple NFT standard for Solana

    New Solana NFT Standard Current Issues The current NFT spec is pretty bad for a few reasons: every NFT requires multiple accounts (3+) the token accou

    null 38 Oct 20, 2022
    Simple Library implemented using HTML, CSS and JavaScript. This is a simple implementation of JavaScript Modules of ES6.

    Awesome-books A single page project with the porpuse of storing books' titles and authors. Built With CSS, HTML & Javascript. How to run in your local

    Saadat Ali 7 Feb 21, 2022
    fardin 8 Oct 18, 2022
    Using Webpack and external API, this website saves and shows players' scores and allows the submission of new scores.

    Microverse Students Leaderboard Microverse Students Leaderboard project that displays scores submitted by different students. All data is preserved in

    Romina Patiño 5 Aug 19, 2022
    Shikhar 4 Oct 9, 2022
    A mod for Mindustry that adds a few items and liquids, and a whole new tier of upgrades, along with arc

    A mod that adds a few items and liquids, and a whole new tier of upgrades, along with arc. Made by Chickenloser and Oreo with help from Duvent.

    null 5 Nov 25, 2022
    Project Cider. A new look into listening and enjoying Apple Music in style and performance. 🚀

    Links Wiki Request Feature Report Bug View The Releases Install Sources Compiling and Configuration For more information surrounding configuration, co

    Cider Collective 5.8k Jan 5, 2023
    A leaderboard created using Leaderboard API service, Webpack, and Gitflow. The user can add a new score and refresh to see his ranking in the leaderboard.

    Leaderboard A leaderboard created using Leaderboard API service, webpack, and gitflow. The user can add a new score and refresh to see his ranking in

    ABDUL ALI 13 Dec 26, 2022
    The website can be used to creat a new game and start adding players and there scores! 🙌

    LeaderBoard Welcome! ?? This Website Allows you to creat your game and add your players score. ScreenShot 1 ScreenShot 2 ScreenShot 3 ScreenShot 4 :--

    Waleed Amjad 5 Aug 30, 2022