Style taxonomy tags

How can I style each tag displayed on top of a post (like different colour for different keywords)?
This is an example of what i want to do :

If you write classes with the name of the topic or tag, you can do it. In this blog that has not been updated in a long time, I am doing it with a limited number of topics:

Then I make css for bg-topic-whatever to style the background of that tag.

Thanks a lot Rick for the quick reply. That’s almost what I wanted!
I was also hoping if random (new) colors can be assigned every time I create a new tag. Any thoughts?

Those do the things.

You could use shuffle to get a random integer and pair that template code with a bunch of color classes you predefine, like bg-color-1, bg-color-2.