<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/if-else-in-css-iozc-msr2" -->

---
title: if/else in CSS | daily.dev
description: There are no conditional statements in CSS, but this may soon change with new @when and @else operator. Currently, the only way to perform a conditional...
canonical: https://daily.dev/posts/if-else-in-css-iozc-msr2
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: if/else in CSS | daily.dev
og:description: There are no conditional statements in CSS, but this may soon change with new @when and @else operator. Currently, the only way to perform a conditional...
og:url: https://daily.dev/posts/if-else-in-css-iozc-msr2
og:image: https://api.daily.dev/og/posts/iozC-MSR2.png
og:image:alt: if/else in CSS
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# if/else in CSS

**[DEV](https://daily.dev/sources/devto)** · 1 min read · 117 upvotes · 4 comments

## Summary

There are no conditional statements in CSS, but this may soon change with new @when and @else operator. Currently, the only way to perform a conditional statement was to use media queries. The new proposal looks much cleaner and very similar to many programming languages. It's not supported by any browser at this moment, it's not even listed on caniuse.com .

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://dev.to/quentindamianino/ifelse-in-css-45f5>

## Community discussion

Top comments from developers on daily.dev.

**@mrakcw** · 0 upvotes

> Wow

**@ardies** · 0 upvotes

> It's good

**@supalakke** · 0 upvotes

> Nice

**@lorezz** · 0 upvotes

> nice, love also the example in the comments

## Similar posts on daily.dev

- [Don’t just attend KubeCon \+ CloudNativeCon, Merge Forward your experience\!](https://daily.dev/posts/don-t-just-attend-kubecon-cloudnativecon-merge-forward-your-experience--l0rpp73x8) · CNCF · 1 upvotes · 0 comments
- [Announcing H2 2026 KCDs](https://daily.dev/posts/announcing-h2-2026-kcds-m96goajm1) · CNCF · 1 upvotes · 0 comments
- [Two months of Open Community Groups](https://daily.dev/posts/two-months-of-open-community-groups-asf52zhbs) · CNCF · 0 upvotes · 0 comments

---

Tags: [#css](https://daily.dev/tags/css)

[View this post on daily.dev](https://daily.dev/posts/if-else-in-css-iozc-msr2)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"if/else in CSS","url":"https://daily.dev/posts/if-else-in-css-iozc-msr2","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/if-else-in-css-iozc-msr2"},"datePublished":"2021-12-26T09:08:17.954Z","dateModified":"2021-12-26T09:08:17.955Z","description":"There are no conditional statements in CSS, but this may soon change with new @when and @else operator. Currently, the only way to perform a conditional...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/af8b8e9b4eab6174739d9ddb3a4740f0","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/af8b8e9b4eab6174739d9ddb3a4740f0","isAccessibleForFree":true,"articleSection":"DEV","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"DEV","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/devto","url":"https://daily.dev/sources/devto"},"commentCount":4,"discussionUrl":"https://daily.dev/posts/if-else-in-css-iozc-msr2","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":117},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":4}],"keywords":"css","timeRequired":"PT1M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"DEV","item":"https://daily.dev/sources/devto"},{"@type":"ListItem","position":3,"name":"if/else in CSS"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/if-else-in-css-iozc-msr2","comment":[{"@type":"Comment","text":"Wow","datePublished":"2022-01-25T21:47:47.698Z","url":"https://daily.dev/posts/iozC-MSR2#c-i2-u6HT9L","author":{"@type":"Person","name":"MrakCw","url":"https://daily.dev/mrakcw","image":"https://media.daily.dev/image/upload/f_auto/v1639233433/avatars/VJzGGk9A8mHkMUHMJKLrv"}},{"@type":"Comment","text":"It’s good","datePublished":"2022-03-28T07:23:58.287Z","url":"https://daily.dev/posts/iozC-MSR2#c-le-Mbctcf","author":{"@type":"Person","name":"Ardies Lebon","url":"https://daily.dev/ardies","image":"https://avatars.githubusercontent.com/u/81700296?v=4"}},{"@type":"Comment","text":"Nice","datePublished":"2022-03-22T03:47:13.719Z","url":"https://daily.dev/posts/iozC-MSR2#c-5wamejN9c","author":{"@type":"Person","name":"supaluck","url":"https://daily.dev/supalakke","image":"https://avatars.githubusercontent.com/u/47309697?v=4"}},{"@type":"Comment","text":"nice, love also the example in the comments","datePublished":"2022-01-17T13:29:29.421Z","url":"https://daily.dev/posts/iozC-MSR2#c-H4YGQ-7IL","author":{"@type":"Person","name":"lorezz","url":"https://daily.dev/lorezz","image":"https://avatars0.githubusercontent.com/u/1153066?v=4"}}]}
```

