Why do we need to override CSS styles?

Can anyone tell me why we do override CSS styles ?

You don’t have to override your own styling, but the way the language is built, this is a highly efficient way to write the styling. I would say it generally helps to avoid repeating yourself. Largely speaking you will tend not to override all properties of a rule, but only some. Like in a Venn diagram:

image

E.g. You have such a headline:

h1 {
  font-size: 3rem;
  color: blue;
  padding: 2rem;
}

When most of your headlines look like this and you sometimes you want to have a red one, you could only override the color:

.headline-red {
  color: red;
}

So you don’t have to repeatedly write:

.headline-red {
  font-size: 3rem;
  color: read;
  padding: 2rem;
}

It is also helpful to organize code and customize styling.

1 Like

Thanks a lot.
:pray:

1 Like