It’s not clear to me what you are trying to do but there is no reason why you couldn’t declare the class name as a variable and re-use it as required.
Your HTML should be minimal anyway but the HTML should also include class declarations as required.
Whether these are applied manually, via PHP (for instance) or JS doesn’t make much difference unless JS is disabled…which some people do.
I’m wondering if you are looking for a CSS pre-processor because, as I said, it’s not clear to me what the ‘issue’ actually is.