# A workaround for hiding empty slots in Chromium

DevFeed: [A workaround for hiding empty slots in Chromium](<https://devfeed.tech/articles/a-workaround-for-hiding-empty-slots-in-chromium-49212.md>)

Original publisher: [Read original article](<https://daverupert.com/2026/06/fix-for-host-has-slot/>)

Author: Dave Rupert

Published: 2026-06-19T04:57:00Z

Content type: tutorial

Language: en

Sources: [Dave Rupert](<https://devfeed.tech/sources/daverupert-com.md>)

Topics: [Web Components](<https://devfeed.tech/topics/web-components.md>), [Chromium](<https://devfeed.tech/topics/chromium.md>), [Web Development](<https://devfeed.tech/topics/web-development.md>), [Document Object Model (DOM)](<https://devfeed.tech/topics/dom.md>)

Tags: [browser](<https://devfeed.tech/tags/browser.md>), [bug](<https://devfeed.tech/tags/bug.md>), [chromium](<https://devfeed.tech/tags/chromium.md>), [css](<https://devfeed.tech/tags/css.md>), [flex](<https://devfeed.tech/tags/flex.md>), [grid](<https://devfeed.tech/tags/grid.md>), [layout](<https://devfeed.tech/tags/layout.md>), [web-components](<https://devfeed.tech/tags/web-components.md>), [webcomponents](<https://devfeed.tech/tags/webcomponents.md>)

## AI overview

A workaround for hiding empty named slots in Web Components when Chromium fails to support the relevant :host(:has([slot])) query. The article explains how this causes ghost gaps in flex or grid layouts and reports a solution that works in Safari, Firefox, and Chrome.

## Source excerpt

Named slots are one of web components' biggest superpowers ✨. Imagine a Button component with an optional icon; in Web Components we don't need a separate Button and IconButton, a single Button component with <slot name="icon"> will do. Or a card component with a handful of predefined slots for image, title, description, price, metadata, etc. Not 100 different cards... one card. Slots are a wonderful way to declaratively compose UI, but one shadow styling challenge that has vexed my team over the years is how to contextually hide a <slot> when there's no slotted content. The problem... ghost gaps The most idiomatic way to check if a particular slot is in-use is to use :host(:has([slot="foo"])). But... In a weird twist to how web component browser-compat bugs tend to go, :host(:has([slot])) works in Safari and Firefox today but doesn't work in Chromium! Chromium not supporting :host(:has([slot])) means we can't query an element's Light DOM contents from the Shadow DOM. That interpretation of encapsulation makes sense (I guess) and in most situations it's not a big problem; an empty slot is like an empty span and probably won't impact rendering. But it becomes a problem when the empty slots appear in a flex or grid layout using gap because unless you hide the element and/or its wrapper, the gap will not collapse in Chromium, so you end up with a "ghost gap". Example: With slot="optional" content in Light DOM Required content Optional content - expected: show content with gap <optional-slot-demo-broken> <div slot="required">Required content</div> <div slot="optional">Optional content - expected: show content with gap</div> </optional-slot-demo-broken> Example: Without slot="optional" content in Light DOM Required content <optional-slot-demo-broken> <div slot="required">Required content</div> <!-- expected: does not show extra whitespace --> </optional-slot-demo-broken> ✅ Works in Safari = wrapper div hidden, no gap ✅ Works in Firefox = wrapper div hidden, no gap ❌ Broken in