Universal CSS properties everyone must use.
Tags: css, webdev, tutorial, beginners
Published: 2020-11-01 14:43:30

When I came across youtube tutorials, I stumbled upon a CSS concept called universal css properties. Lets learn about them in this tutorial.

```

*,*:before, *:after {

box-sizing: border-box ; 
padding: 0 ;
margin: 0 ;  

}
 
```

First lets talk about CSS's universal selector property.

This * selector applies to each and every element in the html file.

So thats why these properties are called Universal CSS properties.

>  *:before ,* :after are pseudo selectors.

Now coming to box-sizing: border-box,

> Border-box tells the browser to account for any border and padding in the values you specify for an element's width and height. If you set an element's width to 100 pixels, that 100 pixels will include any border or padding you added, and the content box will shrink to absorb that extra width. This typically makes it much easier to size elements.
                    <u>- developer.mozilla</u>

 

#### In my words I would say that border-box will make sure that if your width and height of the element is 100px and 100px respectively, it stays that way no matter what padding, margin or border you add.

Before using this property in my CSS files, I faced a lot of issues when I had a div within div and when I added a border it would exceed the outer div width.

It was very annoying and this property fixed all of that. Just include this in your workflow, And you will see the magic.

#### Then coming to padding:0 and margin:0,

Every element in html file has some default padding and margin, so inorder to remove that, we use these two properties.

 Then these were the universal CSS properties given by youtubers and Udemy instructors.

 I would like to give mine on top of these properties.

```

*,*:before,*:after{

padding:0;
margin:0;
box-sizing:border-box;

}
input,textarea{

outline:none

}


button,input[type="submit"]{

outline:none;
border:none;

}

button:hover,input[type="submit"]{

cursor:pointer;
transform: translateY(-0.25em);

}

li,a{
text-decoration:none;
}

```

- When you click on a button or an input of submit button we get an ugly outline in it, So I removed it. You can also remove this property when you want to have border and outline which suits your design purposes. 

- When button is hovered I have added cursor:pointer and given a small animation.

- Then lists(li) and anchor links(a) have text-decoration and I have removed it. 

You can get the complete source code here :

[CSS-universal-selectors](https://github.com/Gautham495/universal-css)


> You can also play along with my CSS properties also!

So thats all for universal selectors.


### <u>My Personal Experience: </u>


Always include the above mentioned CSS properties whenever you start a new project. Remember to include them, It will save a lot of time and actual headache for you in both long run and short run.

### Thank you for reading!

If you like this article, Unicorn it! Heart/Like this one and save it for read later.

### <u>My Other Articles: </u>


- [Create-react-app](https://dev.to/gautham495/creating-a-new-react-app-with-create-react-app-4e9m)

- [Git for beginners](https://dev.to/gautham495/basic-git-knowledge-for-beginners-m4p)

- [Change headers in react with react-helmet](https://dev.to/gautham495/changing-headers-in-react-with-react-helmet-d0d)