To hide an entire Section in Webflow when a Collection List is empty, you’ll need to use the Empty State settings available within the Collection List element.
Assign a class or ID to the main Section that wraps your Collection List (e.g., section-to-hide
).
Publish your site and add this code in the Page Settings under the Before
tag custom code section:
Example (no raw code formatting used here):
Use a basic script:<script>
const emptyState = document.querySelector('.w-dyn-empty');
if (emptyState) {
const section = document.querySelector('.section-to-hide');
if (section) section.style.display = "none";
}
</script>
Adjust the class selectors as needed to match your Webflow project.
To hide a section when a Webflow Collection List is empty, add and detect the Empty State and apply a small script to remove the entire section from view. Webflow doesn't natively allow hiding parent elements based on children's state, so a simple custom script bridges that gap.