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?
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;
}
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.