Not able to understand difference between style and class

as we can use style to change color then why we are using class everywhere.

Simply, classes are used to increase code reusability, modularity etc. When you want to share same styles over many html elements, all you have to do is define a single class and use it on all elements. So that, you will follow DRY principle , and not copy - paste the same code everywhere. In case of any changes to that style , you only need to change from one place which is the same class you define.

1 Like

In addition to what @TonyMontana said, styling via classes (and other selectors) makes maintaining and updating your styles so much easier. If you do everything with inline CSS, then every time you add a new element, you have to figure out all of the appropriate styling and add it to every element. And if you decide that you want to change something about the appearance of your web application (let’s say, make your headers blue instead of red), you would have to go through every line of every html file and make that change.

Inline styling is important to learn, but you very rarely use it in practice.

1 Like