0

I'd like to enable the Dark Mode in Magento 2.

Using plain CSS I know it easily achieved by doing:

@media (prefers-color-scheme: dark) {
  .day.dark-scheme   { background:  #333; color: white; }
  .night.dark-scheme { background: black; color:  #ddd; }
}

How can I implement it in my Magento .less file instead?

I tried something like:

& when (@media = 'prefers-color-scheme: dark') {
  .day.dark-scheme   { background:  #333; color: white; }
  .night.dark-scheme { background: black; color:  #ddd; }
}

but it didn't work.

1 Answer 1

0

You can try below less like.

@black:  #000000;
@black1: #333333;
@white:  #ffffff;
@grey:   #dddddd;
@drak-grey: #555555;
@light-grey: #333333;


@media (prefers-color-scheme: dark) {
    .day.dark-scheme {
        background: @black1;
        color: @white;
    }
    .night.dark-scheme {
        background: black;
        color: @grey;
    }
}
@media (prefers-color-scheme: light) {
    .day.light-scheme {
        background: @white;
        color: @drak-grey;
    }
    .night.light-scheme {
        background: @light-grey;
        color: @black;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.