Webflow sync, pageviews & more.
NEW

How can I set the active tab to the one that is populated when using Webflow for tabs populated by a single CMS element?

TL;DR
  • Assign unique classes or IDs to each Tab Pane and include a hidden “is-populated” element only in the pane with CMS content.
  • Use JavaScript to detect the populated tab by checking for the “is-populated” element, then set that tab as active and remove Webflow’s default active classes.

When using Webflow Tabs with content populated by a single CMS item Collection List, the challenge is that all tabs may appear, but only one contains content, and Webflow doesn't automatically activate that one. You can make the tab with CMS content load as the active tab by following the steps below.

1. Set Up Unique Tab Pane Class

  • Give each Tab Pane a unique class or ID, such as tab-pane-featured, tab-pane-news, etc.
  • This is important to identify which pane has CMS content with custom code.

2. Add Custom Attribute or Indicator in CMS Content

  • Inside each Tab Pane, add a hidden div or span with a unique class, e.g., is-populated, only when the CMS item is rendered.
  • Alternatively, check for a specific text element or wrapper div that only exists in the populated tab.

3. Use JavaScript to Detect the Populated Tab and Set It Active

Paste the following in the Before tag section in your project's Page Settings:

  • This script finds the first tab pane that has actual content and sets its tab button and panel to active.
<script>  window.addEventListener('DOMContentLoaded', function () {    const tabLinks = document.querySelectorAll('.w-tab-link');    const tabPanes = document.querySelectorAll('.w-tab-pane');    for (let i = 0; i < tabPanes.length; i++) {      const pane = tabPanes[i];      if (pane.querySelector('.is-populated')) {        // Remove active classes from all tabs        tabLinks.forEach(link => link.classList.remove('w--current'));        tabPanes.forEach(pane => pane.classList.remove('w--tab-active'));        // Add active class to the detected tab        tabLinks[i].classList.add('w--current');        pane.classList.add('w--tab-active');        break;      }    }  });</script>
🟡 Important: Adjust the .is-populated class to match your hidden indicator or element inside the CMS-bound tab.

4. Disable Webflow’s Default Active Tab

  • Webflow automatically sets the first tab as active by default.
  • In Designer, go to the Tabs component and uncheck "Set as initial state" on the first tab or remove the w--current class from all Tab Links and w--tab-active from all Tab Panes inside the code.

Summary

To set the active tab dynamically when using a single CMS item in Webflow Tabs:

  • Detect the tab pane populated with CMS content using a hidden class or specific element.
  • Use JavaScript to make that tab active.
  • Ensure Webflow’s default active classes aren’t interfering by removing them from the default tab.

This approach ensures only the populated tab loads actively, giving a better user experience.

Rate this answer

Other Webflow Questions