DEV Community

Esther Adebayo
Esther Adebayo

Posted on

2

Panda CSS Conditions

Conditions in Panda allow you to change styles depending on specific states or situations.

For example, if I want to style an SVG element specifically, I can create a condition in the Panda config file.



import { defineConfig } from '@pandacss/dev'

export default defineConfig({
  conditions: {
    extend: {
      icon: "& > svg"
    },
  },
});


Enter fullscreen mode Exit fullscreen mode

To use this condition, I prefix it with an underscore.



function App() {
  return (
    <div
      className={css({
        _icon: {
          color: '#CDCDCD',
        },
      })}
    >
      Conditions in Panda
    </div>
  );
}


Enter fullscreen mode Exit fullscreen mode

This tells Panda only to apply that style when that specific condition is true.

Learn more about Panda CSS with my crash course ⬇️

.

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay