How to separate H2 styling to the CSS section?

How to separate H2 styling to the CSS section?
0

#1

Let’s say I want all H2 elements to have the class text-center, how do I do it once in the CSS stylesheet, without specifying every time when I use the H2 element?


#2

If you want them to be center-aligned without having to assign the “text-center” class to each one of them, you can just do:

h2 {
 text-align:center;
}

#3

As @noyb has said, you don’t need to apply a new class to every h2 element on the page. You can just add text-align: center to generic h2 in your css.