Yes, it is absolutely possible to add dynamic class names to items in a Webflow Collection List using custom JavaScript. This allows you to apply styling based on CMS fields without splitting into multiple Collection Lists.
Here’s how to do it:
style-tag and optionally set it to Display: None so it doesn’t show on the page.
Embed block or in Page Settings > Footer Code).
Example:
const items = document.querySelectorAll('.w-dyn-item'); // Collection List items
items.forEach(item => {
const tagEl = item.querySelector('.style-tag');
if (tagEl) {
const classKey = tagEl.textContent.toLowerCase().replace(/\s+/g, '-'); // slugify
item.classList.add(`style-${classKey}`);
}
});
.style-[value]. .style-featured { background-color: gold; }
.style-archived { opacity: 0.5; }
You can dynamically assign class names to Webflow Collection Items by outputting a CMS field as a hidden element, then using JavaScript to read that value and apply a corresponding class. This gives you flexible styling options without duplicating Collection Lists.