Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 230612

How to force a dark theme?

$
0
0

Hello, I searched a bit and found the solution !

You need to set the color-scheme to dark (otherwise think like scrollbar will stay white) and also add the class dark to the body

// index.html
<head>
  // ...
  <meta name="color-scheme" content="dark" />
  // ...
</head>

<body class="dark">

Then you just need to follow what is (not perfectly) explained in the documentation (in particular the notice) :

To make it easy to integrate a light/dark theme later, what you can do is comment out the @media (prefers-color-scheme: dark) { (don’t foget to comment the close bracket) and add dark class on body, .ios body and .md body that are inside this media.

// theme/variable.scss

:root {
// ...
}


/*@media (prefers-color-scheme: dark) {*/
  body.dark {
    // ...
  }

  .ios body.dark {
    // ...
  }

  .ios ion-modal { // nothing to change here but keep it (not tested)
    // ...
  }

  // ...
  .md body.dark {
    // ...
  }
/*}*/

If you removed the :root part then you can just comment/remove the media and you don’t need to add the dark class in both index.html and variables.scss. But I personnally like the fact that currently it act like I’m forcing the dark mode (and not remplacing the light one by the dark one) and if I remove the class dark in the index.html then it’ll be light mode again (+ <meta color-scheme /> to modify)

And if you want to have a nice status bar in browser/pwa (on mobile) don’t forget to set the meta theme-color ! (Advanced Theming: Quickly Customize App Colors using CSS | Ionic)

// index.html
<head>
  // ...
  <meta name="theme-color" content="#000000" />

Hope it help :slight_smile:


Viewing all articles
Browse latest Browse all 230612

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>