Styling HTML Elements


#1

Is it possible to style every HTML element using CSS?


#2

Hello, and welcome on the forums. Yes it is possible, you simply select body or html it depends on what is the parent element of all HTML elements.

But in some cases like when you want to put a border to each element, using simply body would put a border to the body this is when we can use nth-child() pseudo element which works like an iterator so it sets border on each child element, it can also set even, odd, every third, first three elements of the parent element.

/* simple */
body {
  color: green;
}
/* nth-child */
:nth-child(n) {
  border: 1px solid green;
}

You can learn more about nth-child() on Mozilla Developer Networks

Hope this helps :grinning:


#3

Thank you. And yes, it helped!