How to echo custom styles in css format?

You can use uniqueid() from php. It’ll generate unique id for your css selector.

Or if you use any WordPress core pages like : archive, tags, category pages, please refer following article: 9 Ways to Set Dynamic Body Ids via PHP and WordPress

tech