# For newly created labels, assign a random style

**URL:** https://meta.discourse.org/t/for-newly-created-labels-assign-a-random-style/316577
**Category:** Development
**Created:** [July 16, 2024, 2:56pm UTC](https://meta.discourse.org/t/for-newly-created-labels-assign-a-random-style/316577 "2024-07-16T14:56:39Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![Alteras](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alteras/32/179824_2.png) [@Alteras](https://meta.discourse.org/u/Alteras)
#### Post date: [July 16, 2024, 6:39pm UTC](https://meta.discourse.org/t/for-newly-created-labels-assign-a-random-style/316577/2 "2024-07-16T18:39:09Z")

</div>

Not exactly random, and not at tag creation, but you can do something similar to the [Tag Icons](https://meta.discourse.org/t/tag-icons/109757) component and use the `replaceTagRenderer()` from the plugin-api to modify the html of the tags at view (see [https://github.com/isabella232/discourse-tag-icons/blob/master/common/header.html](https://github.com/isabella232/discourse-tag-icons/blob/master/common/header.html)).

A function like this would take the tag name, map the tag name to a number 1-6 (i.e. encode the string into base 6 and take the last digit/apply modulo), and add it to the HTML string. It wont be random since the style would be determined by tag name, but it would keep the style the same for all users

The original default render tag function is here:

> <https://github.com/discourse/discourse/blob/7d729603b48b9187d7b9fdadd9f3594b3ac01c64/app/assets/javascripts/discourse/app/lib/render-tag.js#L13-L69>

---

_[View the full topic](https://meta.discourse.org/t/for-newly-created-labels-assign-a-random-style/316577)._
