# CSS Protips [](https://github.com/sindresorhus/awesome)
A collection of tips to help take your CSS skills pro.
> For other great lists check out [@sindresorhus](https://github.com/sindresorhus/)'s curated list of [awesome lists](https://github.com/sindresorhus/awesome/).
## Table of Contents
* [Protips](#protips)
* [Support](#support)
* [Translations](#translations)
* [Contribution Guidelines](CONTRIBUTING.md)
## Protips
1. [Use a CSS Reset](#use-a-css-reset)
1. [Inherit `box-sizing`](#inherit-box-sizing)
1. [Use `unset` Instead of Resetting All Properties](#use-unset-instead-of-resetting-all-properties)
1. [Use `:not()` to Apply/Unapply Borders on Navigation](#use-not-to-applyunapply-borders-on-navigation)
1. [Check If Font Is Installed Locally](#check-if-font-is-installed-locally)
1. [Add `line-height` to `body`](#add-line-height-to-body)
1. [Set `:focus` for Form Elements](#set-focus-for-form-elements)
1. [Vertically-Center Anything](#vertically-center-anything)
1. [Comma-Separated Lists](#comma-separated-lists)
1. [Select Items Using Negative `nth-child`](#select-items-using-negative-nth-child)
1. [Use SVG for Icons](#use-svg-for-icons)
1. [Use the "Lobotomized Owl" Selector](#use-the-lobotomized-owl-selector)
1. [Use `max-height` for Pure CSS Sliders](#use-max-height-for-pure-css-sliders)
1. [Equal-Width Table Cells](#equal-width-table-cells)
1. [Get Rid of Margin Hacks With Flexbox](#get-rid-of-margin-hacks-with-flexbox)
1. [Use Attribute Selectors with Empty Links](#use-attribute-selectors-with-empty-links)
1. [Style "Default" Links](#style-default-links)
1. [Intrinsic Ratio Boxes](#intrinsic-ratio-boxes)
1. [Style Broken Images](#style-broken-images)
1. [Use `rem` for Global Sizing; Use `em` for Local Sizing](#use-rem-for-global-sizing-use-em-for-local-sizing)
1. [Hide Autoplay Videos That Aren't Muted](#hide-autoplay-videos-that-arent-muted)
1. [Use `:root` for Flexible Type](#use-root-for-flexible-type)
1. [Set `font-size` on Form Elements for a Better Mobile Experience](#set-font-size-on-form-elements-for-a-better-mobile-experience)
1. [Use Pointer Events to Control Mouse Events](#use-pointer-events-to-control-mouse-events)
1. [Set `display: none` on Line Breaks Used as Spacing](#set-display-none-on-line-breaks-used-as-spacing)
### Use a CSS Reset
CSS resets help enforce style consistency across different browsers with a clean slate for styling elements. You can use a CSS reset library like [Normalize](http://necolas.github.io/normalize.css/), _et al._, or you can use a more simplified reset approach:
```css
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
```
Now elements will be stripped of margins and padding, and `box-sizing` lets you manage layouts with the CSS box model.
#### [Demo](http://codepen.io/AllThingsSmitty/pen/kkrkLL)
**Note:** If you follow the [Inherit `box-sizing`](#inherit-box-sizing) tip below you might opt to not include the `box-sizing` property in your CSS reset.
[back to table of contents](#table-of-contents)
### Inherit `box-sizing`
Let `box-sizing` be inherited from `html`:
```css
html {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
```
This makes it easier to change `box-sizing` in plugins or other components that leverage other behavior.
#### [Demo](https://css-tricks.com/inheriting-box-sizing-probably-slightly-better-best-practice/)
[back to table of contents](#table-of-contents)
### Use `unset` Instead of Resetting All Properties
When resetting an element's properties, it's not necessary to reset each individual property:
```css
button {
background: none;
border: none;
color: inherit;
font: inherit;
outline: none;
padding: 0;
}
```
You can specify all of an element's properties using the `all` shorthand. Setting the value to `unset` changes an element's properties to their initial values:
```css
button {
all: unset;
}
```
**Note:** the `all` and `unset` shorthand isn't supported in IE11.
[back to table of contents](#table-of-contents)
### Use `:not()` to Apply/Unapply Borders on Navigation
Instead of putting on the border...
```css
/* add border */
.nav li {
border-right: 1px solid #666;
}
```
...and then taking it off the last element...
```css
/* remove border */
.nav li:last-child {
border-right: none;
}
```
...use the `:not()` pseudo-class to only apply to the elements you want:
```css
.nav li:not(:last-child) {
border-right: 1px solid #666;
}
```
Here, the CSS selector is read as a human would describe it.
#### [Demo](http://codepen.io/AllThingsSmitty/pen/LkymvO)
[back to table of contents](#table-of-contents)
### Check If Font Is Installed Locally
You can check if a font is installed locally before fetching it remotely, which is a good performance tip, too.
```css
@font-face {
font-family: "Dank Mono";
src:
/* Full name */
local("Dank Mono"),
/* Postscript name */
local("Dank Mono"),
/* Otherwise, download it! */
url("//...a.server/fonts/DankMono.woff");
}
code {
font-family: "Dank Mono", system-ui-monospace;
}
```
H/T to Adam Argyle for sharing this protip and [demo](https://codepen.io/argyleink/pen/VwYJpgR).
[back to table of contents](#table-of-contents)
### Add `line-height` to `body`
You don't need to add `line-height` to each `