# true or false in CSS

DevFeed: [true or false in CSS](<https://devfeed.tech/articles/true-or-false-in-css-121945.md>)

Original publisher: [Read original article](<https://blog.master.dev/true-or-false-in-css/>)

Author: Preethi Sam

Published: 2026-11-06T13:38:19Z

Content type: article

Language: en

Sources: [Master.dev Blog RSS Feed](<https://devfeed.tech/sources/master-dev-blog-rss-feed.md>)

Topics: [CSS](<https://devfeed.tech/topics/css.md>), [selectors](<https://devfeed.tech/topics/selectors.md>), [data type](<https://devfeed.tech/topics/data-type.md>), [Front end](<https://devfeed.tech/topics/frontend.md>), [typesafety](<https://devfeed.tech/topics/typesafety.md>), [Web Development](<https://devfeed.tech/topics/web-development.md>)

Tags: [blog-post](<https://devfeed.tech/tags/blog-post.md>), [boolean](<https://devfeed.tech/tags/boolean.md>), [boolean-type](<https://devfeed.tech/tags/boolean-type.md>), [conditional](<https://devfeed.tech/tags/conditional.md>), [container-queries](<https://devfeed.tech/tags/container-queries.md>), [css](<https://devfeed.tech/tags/css.md>), [css-custom-properties](<https://devfeed.tech/tags/css-custom-properties.md>), [css-variables](<https://devfeed.tech/tags/css-variables.md>), [custom-properties](<https://devfeed.tech/tags/custom-properties.md>), [data-type](<https://devfeed.tech/tags/data-type.md>), [has](<https://devfeed.tech/tags/has.md>), [html](<https://devfeed.tech/tags/html.md>), [inheritance](<https://devfeed.tech/tags/inheritance.md>), [logic](<https://devfeed.tech/tags/logic.md>), [performance](<https://devfeed.tech/tags/performance.md>), [property](<https://devfeed.tech/tags/property.md>), [scope](<https://devfeed.tech/tags/scope.md>), [style-queries](<https://devfeed.tech/tags/style-queries.md>)

## AI overview

CSS has no native boolean data type, but registered custom properties can emulate true/false flags for conditional styling. The excerpt registers `--isBackpack` and `--isDuffel` with syntax `"true | false"`, defaults them to `false`, and disables inheritance. `:has()` sets each flag on `:root` when its checkbox is checked; a named root container then exposes those values to style queries. The example uses `@container` conditions to hide products outside the selected categories, including the combined checkbox state. This replaces long checked/unchecked selector combinations with readable conditions. Registration is recommended in the excerpt for type safety, performance, and avoiding inheritance; a root container name is unnecessary when the queried property is on the direct parent or is inheritable.

## Source excerpt

CSS doesn't have a boolean type, but it does have the true and false keywords. Register a custom property that only accepts them, flip it with :has(), and container style queries turn messy :checked selector combinations into readable conditions.