Notes on Josh Comeau’s Custom CSS Reset

We recently talked with Elad Shechter on his new CSS reset, and shortly after that Josh Comeau blogged his.

We’re in something of a new era of CSS resets where… you kind of don’t need one? There isn’t that many major differences between browsers on default styling, and by the time you’re off and running styling stuff, you’ve probably steamrolled things into place. And so perhaps “modern” CSS resets are more of a collection of opinionated default styles that do useful things that you want on all your new projects because, well, that’s how you roll.

Looking through Josh’s choices, that’s what it seems like to me: a collection of things that aren’t particularly opinionated about design, but assist the design by being things that pretty much any project will want.

I’m gonna go through it and toss out 🔥 flamin’ hot opinions.

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

Heck yes. We used to consider this a global holiday ’round here. Although, with more and more layout being handled by grid and flexbox, I’m feeling like this is slightly less useful these days. When you’re setting up a layout with fr units and flexin’ stuff, the box-sizing model doesn’t come into play all that much, even when padding and border are involved. But hey, I still prefer it to be in place. I do think if it goes into a CSS reset it should use the inheritance model though, as it’s easier to undo on a component that way.

* {
  margin: 0;
}

This is basically why the CSS-Tricks logo “star” exists. I used to love this little snippet in my CSS resets. There was a period where it started to feel heavy-handed, but I think I’m back to liking it. I like how explicit you have to be when applying any margin at all. Personally, I’d rock padding: 0; too, as list elements tend to have some padding pushing them around. If you’re nuking spacing stuff, may as well nuke it all.

html, body {
  height: 100%;
}

Probably a good plan. Josh says “Allow percentage-based heights in the application,” which I can’t say comes up much in my day-today, but what it does is stuff like the body background not filling the space the way you might expect it to.

Too bad body { height: 100vh; } isn’t enough here, but I feel like that’s not as reliable for some reason I can’t think of right now. Maybe something to do with the footer navigation in iOS Safari?

body {
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

I can’t get into the -webkit-font-smoothing: antialiased; thing. I think it tends to make type dramatically thin and I don’t love it. I don’t mind it as a tool, but I wouldn’t globally apply it on all my projects.

I also generally like to put global typographic sizing stuff on the html selector instead, just because the “root” part of rem implies the <html> element — not the <body> — and I like sizing stuff in rem and then adjusting the root font-size at the root level in media queries.

That 1.5 value feels like a good default line-height (more of a 1.4 guy myself, but I’d rather go up than down). But as soon as it’s set, I feel magnetically pulled into reducing it for heading elements where it’s always too much. That could happen via h1, h2, h3 kinda selectors (maybe h4h6 don’t need it), but Josh has some CSS trickery at work with this snippet that didn’t make it into the final reset:

* {
  line-height: calc(1em + 0.5rem);
}

That’s clever in how the 0.5rem goes a long way for small type, but isn’t as big of an influence for large type. I could see trying that on a greenfield project. Prior art here is by Jesús Ricarte in “Using calc to figure out optimal line-height.”

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

Good move for a CSS reset. The block display type there prevents those annoying line-height gaps that always kill me. And you almost never want any of these media blocks to be wider than the parent. I somehow don’t think picture is necessary, though, as it’s not really a style-able block? Could be wrong. I’d probably toss iframe and object in there as well.

p, h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
}

Good move for sure. It’s bad news when a long word (like a URL) forces an element wide and borks a layout. I tend to chuck this on something — like article or .text-content or something — and let it cascade into that whole area (which would also catch text that happens to be contained in an improper element), but I don’t mind seeing it on specific text elements.

If doing that, you probably wanna chuck li, dl, dt, blockquote on that chain. Despite having attempted to research this several times (here’s a playground), I still don’t 100% know what the right cocktail of line-wrapping properties is best to use. There is word-break: break-word; that I think is basically the same thing. And I think it’s generally best to use hyphens: auto; too… right??

#root, #__next {
  isolation: isolate;
}

I don’t quite understand what’s happening here. I get that this is a React/Next thing where you mount the app to these roots, and I get that it makes a stacking context, I just don’t get why it’s specifically useful to have that stacking context at this level. At the same time, I also don’t see any particular problem with it.

All in all — pretty cool! I always enjoy seeing what other people use (and go so far as to suggest) for CSS resets.


Notes on Josh Comeau’s Custom CSS Reset originally published on CSS-Tricks. You should get the newsletter and become a supporter.

inherit, initial, unset, revert

There are four keywords that are valid values for any CSS property (see the title). Of those, day to day, I’d say I see the inherit used the most. Perhaps because it’s been around the longest (I think?) but also because it makes logical sense (“please inherit your value from the next parent up that sets it”). You might see that with an override of a link color, for example.

<footer>
  ©2012 Website — <a href="/contact">Contact</a>
</footer>
/* General site styles */
a {
  color: blue;
}

footer {
  color: white;
}
footer a {
  color: inherit;
}

That’s a decent and elegant way to handle the fact that you want the text and links in the footer to be the same color without having to set it twice.

The others behave differently though…

  • initial will reset the property back to the spec default.
  • unset is weird as heck. For a property that is inherited (e.g. color) it means inherit, and for a property that isn’t inherited (e.g. float) it means initial. That’s a brain twister for me such that I’ve never used it.
  • revert is similarly weird. Same deal for inherited properties, it means inherit. But for non-inherited properties it means to revert to the UA stylesheet. Kinnnnnda useful in that reverting display, for example, won’t make a <p> element display: inline; but it will remain a sensible display: block;.

PPK covered all this in more detail.

I’m glad he found my whining about all this:

Chris Coyier argues we need a new value which he calls default. It reverts to the browser style sheet in all cases, even for inherited properties. Thus it is a stronger version of revert. I agree. This keyword would be actually useful.

Amen. We have four properties for fiddling with the cascade on individual properties, but none that allow us to blast everything back to the UA stylesheet defaults. If we had that, we’d have a very powerful tool for starting fresh with styles on any given element. In one sense: scoped styles!

PPK has a fifth value he thinks would be useful: cascade. The idea (I suppose) is it kinda acts like currentColor except for any property. Sort of like a free variable you don’t have to define that gives you access to what the cascaded value would have been, except you’re going to use it in some other context (like a calculation).


The post inherit, initial, unset, revert appeared first on CSS-Tricks. You can support CSS-Tricks by being an MVP Supporter.

How to Reset WordPress Websites Quickly (Including Multisite)

Life has no CTRL+Z, but thankfully, your WordPress site does. Whether you want to test various themes and plugins quickly, or you just want to wipe the slate clean and start over, resetting your WordPress site is the way to go.

Deleting WordPress and re-installing it is such a hassle. Why not hit the reset button instead and return it to how it was when you first installed it?

In this post, I’ll show you how to reset your WordPress site in a few simple steps.

The second half of the tutorial will cover how easy it is to reset your WordPress site with a single-click on our Hosting, even if it’s a Multisite. This solution is particularly helpful for everyone, since the free reset plugins don’t work with WordPress Multisite installations perfectly.

Ready…Steady…Let’s go.

Still having trouble resetting your WordPress site after reading this post? Let our experts help! Big or small, our awesome support team can help you with any WordPress issue — and for FREE! Whether it’s Monday lunchtime or peak party hours on the weekend, our team is available 24/7.

Prefer a video instead? We have you covered.

How WordPress Works

Before we discuss the solution, let’s understand how WordPress works. You can, of course, skip this section and head to the solution right away, but I suggest you stay a bit.

WordPress is a series of files on your server working in tandem with a database (MySQL or MariaDB) to store and retrieve information.

An inforgraphic showing a quick overview of how WordPress works
The left side serves the right. The right side makes requests to the left.

By default, WordPress ties every installation to a single database on your web host. This database stores all the information of your WordPress site: settings, blog posts, pages, comments, usernames, passwords, links to files, where to find them, etc.

It stores all this information as values under distinct tables in the database.

Think of a database as a huge box with multiple books inside it, aka tables. And each book stores particular information, like comments or settings. And each entry in the book is a value, like your username, email, etc.

If you could reset all the tables in the database to their initial values, aka erase all the pages of all your books, you’d be resetting your WordPress installation.

But this won’t delete the files you’ve uploaded or downloaded to your WordPress site, such as media, themes, plugins, etc. However, most WordPress reset plugins provide an option to delete these files, either selectively or all of them.

Now that you’ve understood the theory, let’s move ahead with the practicals!

How to Reset a WordPress Site
(Standalone Installations)

Step 1: Install and Activate the WP Reset Plugin

The first step is to go to your WordPress Dashboard > Plugins > Add New, search for WP Reset plugin by WebFactory Ltd., and then click Install Now and Activate it.

WP Reset Plugin Download Page Screenshot
You can also download and install the plugin manually.
Screenshot showing How to Install and Activate the WP Reset Plugin
Search for “WP Reset” in WordPress.org’s plugin repo.

If you’re wondering why I chose this plugin over others, it’s the highest-rated WordPress reset plugin with the most installs. It’s well-supported by its developer with regular updates, and it’s totally free!

Step 2: Go to WP Reset Dashboard

Next, go to Tools > WP Reset to open the WP Reset dashboard.

The WP Reset Dashboard, it's warning users what will be deleted and what not on resetting WordPress

You’ll see a warning here saying that resetting will delete all your site’s posts, pages, custom post types, comments, media entries, users, and all the default WP database tables.

However, your media files, plugins, themes, any other uploads, your site’s settings, the logged-in user’s account, they will all remain as is.

You should keep in mind that the media files will not show in your media library even after the reset, though they’ll still be present on your server. We’ll cover how to delete them quickly later.

Step 3: Hit the Reset Button

Scroll down to the last section in the WP Reset dashboard called Reset.

Now, before you type in “reset” and hit the Reset WordPress button, in the section above Reset, you’ll find the Post-reset actions section.

Here, you can instruct WP Reset to Reactivate the current theme (off by default), Reactivate the WP Reset plugin (on by default), and Reactivate all currently active plugins (off by default).

I’ll go with the default options, but if you plan to install the same theme and plugins later, and just want to reset all the other content, checking these options here will save you time later.

Warning: You need to take note that this is 100% destructive. It will wipe out your current WordPress site completely, and there’s nothing you can do to get it back. THERE is NO UNDO! Unless, you’ve taken a backup of your site. If you haven’t, I recommend it highly. You can use UpdraftPlus or Snapshot Pro to do the same.

3...2...1... Reset. And we’re done. It’s that simple!

Cleaning Your Old WordPress Files

The Reset WordPress button is great to restore your site’s database to its initial condition. This ensures that your WordPress installation is back to its shiny new self. But it doesn’t clear out all your site’s old files.

To help you with performing a clean wipe, WP Reset comes with additional Tools in a separate tab.

Warning (Again): WP Reset is not a backup plugin. There is no CTRL+Z. Proceed with extreme caution if you have taken no backups.

Delete Transients

Delete all transients of your WordPress site

Transients are WordPress options with an expiration time. They help with speeding up your site and/or reducing stress on your server’s resources. It perfectly suits transients to act as a cache for the right data. This option deletes all transient-related database entries, including expired, non-expired, and orphaned transient entries.

Clean Uploads Folder

Delete all files and folders of your WordPress site's Upload folder

This will delete all the files in your /wp-content/uploads folder, including any sub-folders and files inside them. It’ll also delete all your media files.

Reset Theme Options

Reset your WordPress site's theme options

If you’re looking for how to reset WordPress themes, this is it. This option will reset settings for not just your active theme, but all your installed themes. However, for this option to work, the theme should use the official WordPress theme modification API. If the theme developer is using some custom methods to save the theme options, this won’t work.

Delete Themes

Delete all the themes in your WordPress site

Clicking this will delete all your themes, including the active one.

Delete Plugins

Delete all the plugins in your WordPress site

This option with delete all plugins except for WP Reset, which will remain active after it deletes all the other plugins.

Empty or Delete Custom Tables

Empty or delete all the custom tables in your WordPress database

If you have any custom tables in your database with wp_ prefix, this option will either empty or delete them. Emptying (truncating) removes all content from the tables, but keeps their structure intact. Deleting (dropping) removes the tables completely from the database.

Delete .htaccess File

Delete the .htaccess of your WordPress installation

This action deletes the .htaccess file in your WordPress installation’s root folder (not recommended unless you know what you’re doing). If you just want to edit the .htaccess file from your dashboard, you can use the free WP Htaccess Editor plugin from the same authors. Plus, it automatically creates backups of your .htaccess file as you edit it.

Advanced WordPress Reset with WP-CLI

You can execute all the tools available in the WP Reset plugin interface with WP-CLI. Run wp help reset to get a list of the commands available.

Using WP Reset through WP-CLI command line interface

Additional help for every command is available via the default WP-CLI help interface. Do note that you need to confirm all your actions for the sake of security.

If you want to skip confirmation for the commands, use the --yes option. remember though, as with GUI, there’s no going back here too!

How to Reset WordPress Multisite

There’s no free plugin, including both the highly rated WP Reset and Advanced WordPress Reset, which reset WordPress Multisite installations perfectly.

In a Multisite setup, WP Reset plugin disables itself in the Network Admin dashboard. This is to prevent unnecessary harm to the entire Multisite network, since it’s not tested to work with it.

WP Reset is not totally compatible with Multisite
WP Reset team warns users against using it in Multisite setups.

WPMU DEV Hosting to the Rescue

When you use WPMU DEV Hosting to convert your standard WordPress installation to a Multisite network (WP-MU), he automatically takes a backup of your complete site.

A very smart and time-saving feature!

You can identify this backup by its Type value “Pre-Convert to Multisite.”

The WPMU DEV Hosting Dashboard
Easy, automatic backup pre-Multisite setup.

Thanks to this backup, you can reset your WordPress Multisite to how it was before. I recommend you to take a New Backup before you restore the old backup, just in case you change your mind and want to go back.

To reset the WordPress Multisite, click on the three dots icon on the far right end of the backup listing, and then select Restore from the drop-down menu.

Restoring backups at the click of a button in WPMU DEV Hosting
‘1-Click Restore’ will change your development life forever.

And………tadaaaa!!! WP Reset has revived your WordPress Multisite as a single entity. As long as you have a backup, you have unlimited lives to play out this game!

Subsite Resets in a WordPress Multisite

What if you don’t want to reset the entire WordPress Multisite network, but just reset one subsite on it? You have two options here:

1. Complete Reset: Delete the subsite and re-create it with the same name. Not only will your subsite be as good as new, you’ll also delete all its media, themes, plugins, and any other uploads. A total reset of your subsite.

Resetting a Single Subsite on WordPress Multisite network by deleting and recreating it
Deleting subsites is a breeze in the latest WordPress version.

2. Database Reset: Use a plugin such as WP Reset to restore the subsite to its initial state. You must follow the same instructions as you would with a standalone WordPress installation. With this method, you won’t lose the subsite’s files. However, just like resetting non-WP-MU sites, the media won’t be visible in your subsite’s media library after the reset.

Fret not! You’ll still have the option to delete them all, under WP Reset > Tools tab. Note that the WP Reset team suggests, “We don’t recommend to resetting the main site.” It’s up to you though. As long as you have a reliable backup and the will to take a risk, it’s worth it!

WP Reset says that "we don't recommend to resetting the main site. Sub-sites should be OK."
Don’t use WP reset on the main site of your Multisite network.

Warning (Yet Again): Take backups before you try to reset anything. I can’t stress this enough.

Live. Die. Reset.

Debugging WordPress is hard, time-consuming, and often frustrating. It can take hours to find, test, and fix even the smallest bugs. Resetting your WordPress installation with just a single click makes your life easier, so that you can test and debug various themes and plugins quickly and efficiently.

WPMU DEV’s Fully Managed WordPress Hosting is made by developers for developers. No bloat or fluff added. Just the tools you need to get your job done without pulling your hair out.

Also, it’s the closest you’ll come to feeling as badass as Tom Cruise, unless you’re actually Tom Cruise. In that case, we can definitely fulfill your need for speed, should you accept this mission.

CSS Remedy

There is a 15-year history of CSS resets. In fact, a "reset" isn't really the right word. Tantek Çelik's take in 2004 was called "undohtml.css" and it wasn't until a few years later when Eric Meyer called his version a reset, that the word became the default term. When Normalize came around, it called itself a reset alternative, which felt right, because it wasn't trying to obliterate all styles, but instead bring the base styles that browsers provide in their User Agent Stylesheet in line with each other.

We've taken a romp through this history before in Reboot, Resets, and Reasoning. Every single take on this — let's call them "base" stylesheets — has a bit of a different angle. How much does it try to preserve the UA defaults? How opinionated does it get? How far back does it consider for browser support?

Along comes CSS Remedy (they say it's not ready for usage), with yet another different spin:

Sets CSS properties or values to what they would be if the CSSWG were creating the CSS today, from scratch, and didn't have to worry about backwards compatibility.

Fascinating to think about.

CSS Remedy re-draws the line for what is opinionated and what isn't. I'd say that something like * { box-sizing: border-box; } is a fairly strong opinion for a base stylesheet to have. No UA stylesheet does this, so it's applying a blanket rule everywhere just because it's desirable. It's definitely desirable! It's just opinionated.

But not having border-box be the default is considered a CSS mistake. So if CSS Remedy is what a UA stylesheet would be if we were starting from scratch, border-box isn't opinionated; it's the new default.

Sadly, we probably can never have a fresh UA stylesheet in browsers, because the danger of breaking sites is so high. If Firefox shipped some new modernized UA stylesheet that was tastefully done and appears to be nice, but only until you browse around the billion websites that weren't built to handle the new CSS being applied to them, them people would blame Firefox — and not incorrectly. Gracefully handling legacy code is a massive strength of the web and something that holds us back. It's more the former than the latter, though.

It's been fun watching Jen think through and gather thoughts on stuff like this though:

I agree! That little space below images has confounded an absolute ton of people. It's easy enough to fix, but it being the fault of vertical-align is a bit silly and a great candidate for fixing in what would be a new UA stylesheet.

I tossed the in-progress version into the comparison tool:

See the Pen
HTML Kitchen-sink
by Chris Coyier (@chriscoyier)
on CodePen.

Direct Link to ArticlePermalink

The post CSS Remedy appeared first on CSS-Tricks.