Dark Mode: Find It or Build It

Dark Mode: Find It or Build It

by Andrew Uyeno -
Number of replies: 17

I want dark mode!

Moodle is among the last applications I have to use that still blares white. This is especially annoying at night.

I'd appreciate any comments or corrections on the following.

  1. I believe there is no dark mode setting. Is that correct?
  2. I believe nobody at Moodle is creating a dark mode feature now and nobody there is planning to.
  3. Is there a free dark mode plug in I can download? If not, why doesn't it exist?
  4. If I want to create it myself, how much work would it be to learn how to do so? I have very little programming experience.
Thanks!
Average of ratings: Useful (1)
In reply to Andrew Uyeno

Re: Dark Mode: Find It or Build It

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Hi Andrew,
  1. I believe you are correct.
  2. Again, I believe your are correct. I think this is mainly due to the fact that Moodle is mostly used for schools and businesses that work in brightly lighted rooms. Dark modes are not a good fit for that.
  3. Sure. It is called a theme. Different ones have more settings, but you go through all the color options until you wind up with what you want. One of them should let you achieve what you are looking for.
  4. It can be quit time consuming, but in the case of themes, you do not have to start from scratch as you can make a child theme that basically just adds your changes to the main theme you are working with.
Average of ratings: Useful (1)
In reply to AL Rachels

Re: Dark Mode: Find It or Build It

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
Don't do it as a new theme!!

Switching themes is an expensive exercise on both the web server, and the users desktop - we did have a theme switcher plugin submitted to the plugins db with the idea it would be used as a dark-mode style tool, but it didn't quite work right (I did really like the UI they provided for allowing the switching though.)

IMO the right way to do this would be to create a tool_darkmode plugin, 

add a Switch in the header or the footer of the page like the theme switcher plugin we reviewed (but unfortunately rejected) did:


Then save that value (on/off) as a user preference.

Then use one of the output callbacks to add a class to the body tag when that user-preference is set:
$PAGE->add_body_class('darkmode');

Then if you have a custom theme, you could have some custom css in your theme that simply targets darkmode or you could use one of the callbacks and allow the user to add custom css to the tool_darkmode plugin.

The idea is to not have to switch themes at all, but simply target when darkmode is enabled using a class on the body tag - it will be a lot more efficient/safer etc.
Average of ratings: Useful (4)
In reply to Dan Marsden

Re: Dark Mode: Find It or Build It

by Andrew Uyeno -
Dan, thanks for this response! I am not sure I understood it all as I'm not a technically advanced administrator. My questions:

(1) How does one create a tool or a plugin? Is this difficult for a non-technical person to do?
(2) How does the workload compare to switching themes?

Thanks!
In reply to Andrew Uyeno

Re: Dark Mode: Find It or Build It

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
ah - when you said "Build it" - we all assumed you had development capabilities smile - if you don't have development capabilities, it's not something that will be easy to implement on your own. Hopefully one day someone will create a plugin to let you do this.
In reply to Dan Marsden

Re: Dark Mode: Find It or Build It

by Rajneel Totaram -
Picture of Moodle HQ

A few years back I added dark mode support to a custom theme for my previous institution. My approach was similar to what Dan recommends, except that everything was bundled into our custom theme (since we only used one theme throughout the entire site).

Our custom theme had a switch to allow users to toggle between light and dark mode. This would get saved as a user preference. The theme also included CSS styles for dark mode which were compiled and cached together with the default light mode CSS.

In the layout files of the custom theme, fetch the user preference for the theme mode and apply the class "darkmode" to the body element if the user prefers dark mode.

The dark mode CSS styles were put into a new SCSS file (darkmode.scss) such as:

// Dark mode colour scheme
.darkmode {
  background-color: $body-bg-dark !important;
  color: $body-color-dark; .card { background-color: darken($color: $body-bg-dark, $amount: 2); border: 1px solid darken($color: $body-bg-dark, $amount: 4); } #region-main { background: $body-bg-dark; ...
  }
  ...
  ...
}

With this approach, toggling between dark and light mode did not require switching themes.
There are a lot of places in Moodle where the Bootstrap bg-white class is used. So you will have to override background colour of those elements in the dark mode SCSS file (Or you could override the respective template files and remove the bg-white class.)

One word of caution if you are considering adding dark mode support to your Moodle site - think about your existing user-generated content such as pages, books, forum posts, quiz questions. If these contents contain inline CSS styles such as background or font colour, then you could potentially run into some poor colour contrast issues which may make the content difficult to read. For example, if some user generated content has font colour set as black, then switch to dark mode will result in black text on a dark background.

I'd suggest to keep sections where there is user-generated content to have a light grey background.

Hope this helps.

Average of ratings: Useful (1)
In reply to AL Rachels

Re: Dark Mode: Find It or Build It

by Andrew Uyeno -
It sounds like creating a new theme is not a great idea for me. I'd be satisfied with less blaring white and don't require a maximally dark look.

Do you have a suggestion for a theme or how I should learn to switch them? Or do I just need to read through Moodle Theme Forums and a bunch of documentation?


In reply to AL Rachels

Re: Dark Mode: Find It or Build It

by mubarek muhammed -
"For individuals who have knowledge about coding, they can utilize the following code to implement dark and white modes in Moodle." but it is not advisable for sequrity.

<button onclick="var elements = document.querySelectorAll('*'); for (var i = 0; i < elements.length; i++) { elements[i].style.backgroundColor = 'black'; elements[i].style.color = 'white'; }">Toggle Dark Mode</button>


In reply to Andrew Uyeno

Re: Dark Mode: Find It or Build It

by Matthias Giger -
Picture of Particularly helpful Moodlers
In reply to Matthias Giger

Re: Dark Mode: Find It or Build It

by Andrew Uyeno -
Ok, I will have some time soon to read this. Thanks for doing this!

How difficult is it to implement this for a non-technical person? I barely know what CSS stands for. I have absolutely no idea where to place any of the code from that website.
In reply to Andrew Uyeno

Re: Dark Mode: Find It or Build It

by Matthias Giger -
Picture of Particularly helpful Moodlers
In case you just want one Moodle page in dark mode, you can post all the code together into a text label.

If you want it for your whole Moodle installation, you have to make sure that the "script for the dark mode" is available on all Moodle pages (e.g. include it in the additional html section in the administration).

Feel free to ask, in case you need some more detailed instruction.
Average of ratings: Useful (1)
In reply to Andrew Uyeno

Re: Dark Mode: Find It or Build It

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

I just installed the "Dark Moodle" extension for Chrome, a dark mode designed especially for Moodle! Although it is said to be for Université Bretagne Sud (UBS) in France, the extension works fine on my computer without me having any connection to UBS.

At first glance, the rendering is excellent!

Congratulations and thanks to Fyelne, the author of this excellent extension!

Chrome: https://chrome.google.com/webstore/detail/dark-moodle/hblgmffbmddipnmjboehgpbpmmmkhdom➚
Firefox: https://addons.mozilla.org/en-US/firefox/addon/moz-dark-moodle/➚

MoodleForum_20230430_2352.png

MoodleForum_20230430_2353.png

Average of ratings: Useful (2)
In reply to Dominique Bauer

Re: Dark Mode: Find It or Build It

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
Interesting. Thanks for sharing. I will experiment with this a little.
In reply to Dominique Bauer

Odp: Re: Dark Mode: Find It or Build It

by Piotr F -
Thanks, looks nice.
On my Firefox and Chrome, this addon reads:
Can't read and change data on this site.
In reply to Andrew Uyeno

Re: Dark Mode: Find It or Build It

by Eduardo Kraus -
Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Yesterday, I officially launched the moodle-local_boost_dark repository and submitted it for approval on Moodle Tracker under reference CONTRIB-9761. This plugin is designed to provide a dark theme that integrates seamlessly with Boost and any other Bootstrap-based theme.

The core innovation lies in the use of the [data-bs-theme] tag from Bootstrap, which enables smooth and standardized switching between light and dark themes. This approach ensures the implementation is flexible and adheres to Bootstrap best practices, allowing compatibility with future developments and other systems utilizing the framework.

Average of ratings: Useful (1)
In reply to Eduardo Kraus

Ri: Re: Dark Mode: Find It or Build It

by Lorenzo Malferrari -

Thank you very much. I really want to use it. Will it be possible to download it officially soon? Or will I have to go through git?

In reply to Lorenzo Malferrari

Re: Ri: Re: Dark Mode: Find It or Build It

by Eduardo Kraus -
Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Hello, Lorenzo! 😊

I'm very happy to see your enthusiasm for using the Dark Mode feature! 🌓

Currently, the official request for Dark Mode has been submitted for approval and is awaiting validation. You can follow all the progress on the official Moodle tracker link: CONTRIB-9761.

In the meantime, if you're comfortable using Git, you can access the code directly from there to test it before the official release. This could be an incredible opportunity to try out the feature and even share feedback with the community! That way, you not only enjoy it early but also contribute to refining this highly anticipated feature.

Eduardo Kraus
Teacher and programmer 🚀