Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Access Theme Colors Through SX in Material UI

How do I access the colors of the theme through using sx? I tried below but it doesn't work.

<Card
  sx={{
    border: "2px solid primary.main",
  }}
>
like image 694
Joseph Avatar asked Dec 05 '25 15:12

Joseph


1 Answers

As an alternative, you should be able to do:

<Card sx={{border: "2px solid", borderColor: "primary.main"}}>

The shorthand "border" doesn't seem to access the theme colors properly. Hope that's helpful.

Update: Just wanted to add to this that you could also use a function value to set the border color according to your theme.

    <Card sx={{border: "2px solid", borderColor: (theme) => theme.palette.primary.main}}>
like image 98
Tim Hallowell Avatar answered Dec 08 '25 07:12

Tim Hallowell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!