Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Moodle App Remote Themes: Difference between revisions

From MoodleDocs
No edit summary
(Update migration status and path)
 
(28 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{Work in progress}}
{{Template:Migrated|newDocId=/general/app/customisation/remote-themes}}
== How to create your own theme ==
{{Moodle App (Ionic 5)}}
Due to a framework update (Ionic 1 to Ionic 3), Moodle app version 3.5 onwards is not compatible with the existing custom themes / styles. You can keep your current style sheet so they will work with the Moodle Classic app or old Moodle Mobile versions.


In order to do that, you just need to add this line at the end of your existing theme:
== How do Remote Themes work? ==
<code css>
/* 3.5 styles */
</code>


And add below this line your 3.5 onwards styles.
When you enter a site, it downloads any file configured on the <code>mobilecssurl</code> administration field and injects the styles in the app. Every time you change between sites, each style will be enabled or disabled appropriately.


See the following file for an example of a theme with styles for the old and new versions of the app:
The styles will remain enabled in the login page, but any other page that is not related with a specific site will use the default styles. For example, pages to add or remove sites cannot be customised with Remote Themes.


https://gist.githubusercontent.com/crazyserver/ed49913ac40e606c8ce29696b1b3669f/raw/9ad3549140a77f01c86267c42b85e4fb2505577e/moodlemobileapp.css
== How can you create your own theme? ==


This example above is not complete, there are many more colors and styles you can change. It has some clarifications and you can use it as an start for your personalization.
First of all, Remote Themes are only available for sites that purchased a Premium subscription for the Moodle App. You can check the different plans in [https://apps.moodle.com the Apps Portal]. If you want, you can follow the instructions in this document without purchasing a subscription and it will work in your development environment.


In order to create your own theme we recommend to use the proper webapp. Those will require [https://docs.moodle.org/dev/Moodle_Mobile_development_using_Chrome_or_Chromium Chrome or Chromium browser] and use the inspection tool to check the classes you need to change. To test your theme loads corretly you should exit and enter the site again so the new file will be reloaded.
In order to create your own theme, we recommend that you use the app from [https://master.apps.moodledemo.net master.apps.moodledemo.net] and check the styles using the browser inspector. You can use any Chromium-based browser, but you should launch it with some special arguments. You can read more about that in the [[Using the Moodle App in a browser]] page. If you need to test a different version of the app, you can also use [https://integration.apps.moodledemo.net integration.apps.moodledemo.net] for the latest development version or [[Moodle App Docker Images|the Docker images]] for anything more specific.


=== Moodle app 3.5.0 onwards (Ionic 3) ===
Once you have everything ready, you can configure your theme by going to "Site administration > Mobile app > Mobile appearance" in your site and setting the <code>mobilecssurl</code> field to a url pointing to a CSS file. This file can be placed inside your Moodle installation in your custom theme, inside a local plugin, or hosted elsewhere.
{{Moodle Mobile 3.5}}
Webapp to test 3.5 onwards: https://mobileapp.moodledemo.net/


You can check Ionic version 3 documentation for more info: https://ionicframework.com/docs/
You can get started with the following example, and you should see the background of the top bar change to red once you log into the app:


=== Styles based on platform ===
<syntaxhighlight lang="css">
{{Moodle Mobile 3.6}}
body {
The ion-app tag will receive classes with all the platform information based on the following rules:
    --core-header-toolbar-background: red;
}
</syntaxhighlight>
 
=== Applying theme changes during development ===
 
For performance reasons, the app caches the styles after you log in for the first time. So if you make any changes, you won't see them unless you log out and log in again. However, there is a faster way to update them. You can also open the Preferences page in the app and click on the "Synchronise now" button. This will download the files again, and you can use this method to iterate on your styles while you make the theme.
 
The file can also be cached by the browser, so when you do this make sure to [https://developer.chrome.com/docs/devtools/network/reference/#disable-cache disable network cache] as well.
 
=== Knowing what to style ===
 
Depending on how much you want to customise the UI, you'll need to do different things.
 
The application defines some [https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties CSS variables] that can help you customise basic styles, like the one we used in our example above to change the background color of the header toolbar. You can find these variables in the source code, the main ones are defined within [https://github.com/moodlehq/moodleapp/blob/master/src/theme/theme.light.scss theme.light.scss] and [https://github.com/moodlehq/moodleapp/blob/master/src/theme/theme.dark.scss theme.dark.scss], and you can find others within component styles.
 
If you need anything more specific, the application is built using [https://ionicframework.com/docs/theming/basics the Ionic Framework], so reading their documentation can help you understand how the UI works and which components are available. We have some custom components that you won't find listed on their documentation, but most of them built on top of Ionic's.
 
Finally, if you need to style something even more specific, you can always [https://github.com/moodlehq/moodleapp browse the source code] to see how a specific page is built. You can also use the [https://developer.chrome.com/docs/devtools/dom/ Elements Panel] of your browser to inspect styles and debug anything that isn't working as you'd expect. Depending what you are trying to do, remember that this is only a development environment and it may not work correctly in a native device. If you are doing anything complicated, make sure to double check using a real device to see that everything looks good.
 
Notice that you will often need to use <code>!important</code> if you're overriding component styles directly, without using any variables. That's because the default styles are usually scoped to the Angular component, and you won't be able to provide more [https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity specificity] in your selectors.
 
=== Working with colors ===
 
The main color of the app is Moodle Orange, but you can change it by using the <code>--brand-color</code> variable. Other than the overall brand color, there are also some specific variables for other colors.
 
==== Basic colors ====
 
These are the variables used to define the basic color palette used throughout the app:
 
* <code>--white</code> and <code>--black</code>.
* <code>--gray</code>, <code>--gray-light</code>, <code>--gray-lighter</code>, <code>--gray-dark</code> and <code>--gray-darker</code>.
* <code>--red</code>, <code>--red-light</code> and <code>--red-dark</code>.
* <code>--green</code>, <code>--green-light</code> and <code>--green-dark</code>.
* <code>--blue</code>, <code>--blue-light</code> and <code>--blue-dark</code>.
* <code>--yellow</code>, <code>--yellow-light</code> and <code>--yellow-dark</code>.
* <code>--purple</code> and <code>--turquoise</code> (these don't define any variants).
 
==== Semantic colors ====
 
The basic colors are not used directly too often. Instead, the following semantic colors are used:
 
* <code>--primary</code> (derived from <code>--brand-color</code>).
* <code>--danger</code> (derived from <code>--red</code>).
* <code>--warning</code> (derived from <code>--yellow</code>).
* <code>--success</code> (derived from <code>--green</code>).
* <code>--info</code> (derived from <code>--blue</code>).
* <code>--light</code> (derived from <code>--gray-lighter</code>).
* <code>--medium</code> (derived from <code>--gray-light</code>).
* <code>--dark</code> (derived from <code>--black</code>).
 
 
Each of these also define other variants: <code>rgb</code>, <code>contrast</code>, <code>contrast-rgb</code>, <code>shade</code> and <code>tint</code>. If you want to modify any of these, it won't suffice with changing the base color they are derived from, because there are limitations and you'll have to override each variant manually.
 
For example, if you want to override the primary color, you'll need to override the following variables:
 
<syntaxhighlight lang="css">
body {
    --ion-color-primary: #006600;


* '''platform-android''': on a device running Android.
    /* RGB list of the color */
* '''platform-cordova''': on a device running Cordova.
    --ion-color-primary-rgb: 0,102,0;
* '''platform-core''': on a desktop device.
* '''platform-desktop''': on a device running Electron.
* '''platform-ios''': on a device running iOS.
* '''platform-ipad''': on an iPad device.
* '''platform-iphone''': on an iPhone device.
* '''platform-linux''': on a device running Linux.
* '''platform-mac''': on a device running MacOS.
* '''platform-mobile''': on a mobile device.
* '''platform-mobileweb''': in a browser on a mobile device.
* '''platform-phablet''': on a phablet device.
* '''platform-tablet''': on a tablet device.
* '''platform-windows''': on a device running Windows.


Also ios, md and wp classes will be added to know if iOS design, Material design and Windows Phone guidelines is being used.
    /* Black or white, depending on which color gives more contrast */
    --ion-color-primary-contrast: #ffffff;


You can use css rules ion-app.platform-* to have different styles based on platform.
    /* RGB version of the contrast color */
    --ion-color-primary-contrast-rgb: 255,255,255;


=== Styles based on Moodle version ===
    /* Slightly darker color. (mix 12% of black) */
{{Moodle Mobile 3.6}}
    --ion-color-primary-shade: #005a00;


Starting from version 3.6.0 of the app you can style the app depending on the version of the Moodle site. The body tag contains classes that indicate the version of the site, you can restrict CSS rules to a specific version by prepending one of these classes to the selector. For example, when accessing a 3.6.1 site these classes are present in the body tag: "version-3", "version-3-6", "version-3-6-1".
    /* Slightly lighter color. (mix 10% of white) */
    --ion-color-primary-tint: #1a751a;
}
</syntaxhighlight>


=== Showing course summary image on course page ===
==== Specific colors ====
{{Moodle Mobile 3.6}}
 
By default course summary images has been hidden to reduce scrolling when entering a course. If you want to recover the previous behaviour, you can use the following css on your remote theme:
Other than the basic and semantic colors, other components and pages define their own variables that you can override. You can look at the source code to find more, but these are some of the most relevant:
 
<syntaxhighlight lang="css">
body {
    /* Page background */
    --background-color: white;
    --ion-background-color-rgb: 255, 255, 255;
 
    /* Main text color */
    --text-color: black;
    --ion-text-color-rgb: 0, 0, 0;
 
    /* Text used in categories and secondary content */
    --subdued-text-color: gray;
 
    /* Links text */
    --core-link-color: blue;
}
</syntaxhighlight>
 
=== Targeting different environments ===
 
The <code>html</code> and <code>body</code> elements contain classes that indicate the environment the app is running on.
 
==== Platform ====
 
The <code>html</code> element indicates which platform the app is running on. For example, you can specify styles that will only apply to iOS by prepending them with <code>html.ios</code>, or <code>html.md</code> for Android:
 
<syntaxhighlight lang="css">
/* Red toolbar in iOS */
html.ios body {
    --core-header-toolbar-background: red;
}
 
/* Green toolbar in Android */
html.md body {
    --core-header-toolbar-background: green;
}
</syntaxhighlight>
 
==== Moodle App and Moodle site versions ====
 
The <code>body</code> element indicates the versions of the app and the Moodle site, so you can restrict CSS rules to a specific version by prepending one of these classes to the selector. For example, when accessing a 3.11.2 site using the 3.9.5 app the following classes will be present in the body:
 
* <code>version-3</code>
* <code>version-3-11</code>
* <code>version-3-11-2</code>
* <code>moodleapp-3</code>
* <code>moodleapp-3-9</code>
* <code>moodleapp-3-9-5</code>
 
 
And here's how to use them:
 
<syntaxhighlight lang="css">
/* Red toolbar for Moodle App version 3.9.X */
body.moodleapp-3-9 {
    --core-header-toolbar-background: red;
}
 
/* Green toolbar for all other versions */
body {
    --core-header-toolbar-background: green;
}
</syntaxhighlight>
 
==== Application theme ====
 
The application uses a light theme by default, but it adds the <code>dark</code> class to the <code>body</code> element when it is using a dark theme:
 
<syntaxhighlight lang="css">
/* Red toolbar for the Light Theme */
body {
    --core-header-toolbar-background: red;
}
 
/* Green toolbar for the Dark Theme */
body.dark {
    --core-header-toolbar-background: green;
}
</syntaxhighlight>
 
Bear in mind that you can disable Dark Mode for all your users following [https://docs.moodle.org/en/Moodle_app_guide_for_admins#Disabled_features the guide for admins (Disabled features)].
 
==== Combining classes ====
 
Of course, you can combine any of these classes to create more granular styles.
 
Let's say you want to have a red toolbar only in iOS, with the Dark Theme, for a Moodle site running 3.11.X:
 
<syntaxhighlight lang="css">
html.ios body.version-3-11.dark {
    --core-header-toolbar-background: red;
}
</syntaxhighlight>
 
=== Styling the Shadow DOM ===
 
Ionic is a set of web components, and uses the [https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM Shadow DOM] to encapsulate them and make them more opaque to developers and users (hiding markup structure, style, and behavior), thus avoiding conflicts with existing rules.
 
This makes it more difficult to personalise and change some parts of those components. However you can check [https://ionicframework.com/docs/theming/css-shadow-parts#ionic-framework-parts the official Ionic documentation] to see which parts are customisable.
 
For example, if you look at [https://ionicframework.com/docs/api/button#css-shadow-parts the documentation for an <code>ion-button</code>], you can style it this way:
 
<syntaxhighlight lang="css">
/* Disable text transformations */
ion-button::part(native) {
    text-transform: none;
}
 
/* Use a red background by default */
ion-button {
    --background: red;
}
 
/* Use a yellow background for buttons with the "my-custom-class" class */
ion-button.my-custom-class {
    --background: yellow;
}
</syntaxhighlight>
 
You can learn more about the Shadow DOM in the following resources:
 
* [https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM Using shadow DOM - Web Components | MDN]
* [https://ionicframework.com/docs/theming/css-shadow-parts CSS Shadow Parts - Ionic Documentation]
* [https://ionicframework.com/blog/shadow-dom-in-ionic-and-why-its-awesome/ Shadow DOM in Ionic (and Why it's Awesome) - Ionic Blog]
 
=== Supporting older versions of the app ===
 
If you need to support different versions of the app, or you're upgrading your theme from an older version, you should read the [[Moodle App Remote Themes Upgrade Guide]].
 
== Common customisations ==
 
In this section you will find a list of some common customisations you may want to add to your Remote Theme.
 
=== Header toolbar ===
 
The header toolbar has a bottom border that you can disable or customise, along with other parts:
 
<syntaxhighlight lang="css">
/* Background */
ion-header ion-toolbar {
    --core-header-toolbar-background: red;
}
 
/* Bottom border */
ion-header ion-toolbar {
    --core-header-toolbar-border-width: 2px; /* Use 0 to disable it */
    --core-header-toolbar-border-color: green;
}
 
/* Text and buttons */
ion-header ion-toolbar {
    --core-header-toolbar-color: blue;
}
 
ion-header ion-toolbar.in-toolbar h1,
ion-header ion-toolbar.in-toolbar h2 {
    font-weight: normal;
}
</syntaxhighlight>
 
=== Bottom tab bar (main menu) ===
 
<syntaxhighlight lang="css">
ion-tab-bar.mainmenu-tabs {
    /* Background */
    --core-bottom-tabs-background: red;
    --core-bottom-tabs-background-selected: transparent;
 
    /* Tab icons */
    --core-bottom-tabs-color: blue;
 
    /* Selected tab icon */
    --core-bottom-tabs-color-selected: green;
 
    /* Badges */
    --core-bottom-tabs-badge-text-color: black;
    --core-bottom-tabs-badge-color: white;
}
</syntaxhighlight>
 
=== Top tabs ===
 
<syntaxhighlight lang="css">
core-tabs, core-tabs-outlet {
    /* Background */
    --core-tabs-background: red;
 
    /* Tab */
    --core-tab-background: red;
    --core-tab-color: white;
 
    /* Selected tab */
    --core-tab-color-active: blue;
    --core-tab-border-color-active: blue;
    --core-tab-font-weight-active: bold;
}
</syntaxhighlight>
 
=== Items ===
 
<syntaxhighlight lang="css">
body {
    /* Background */
    --ion-item-background: green;
 
    /* Divider */
    --item-divider-background: red;
    --item-divider-color: blue;
 
    /* Empty Divider */
    --spacer-background: yellow;
}
</syntaxhighlight>
 
=== Progress bar ===
 
<syntaxhighlight lang="css">
core-progress-bar {
    --core-progressbar-height: 4px;
    --core-progressbar-color: red;
    --core-progressbar-text-color: green;
    --core-progressbar-background: blue;
}
</syntaxhighlight>
 
=== More page ===
 
<syntaxhighlight lang="css">
/* Icons */
page-core-mainmenu-more {
    --core-more-icon: red;
}
 
/* Target a specific icon */
page-core-mainmenu-more .addon-privatefiles-handler ion-icon {
    color: green !important;
}
 
/* Items */
page-core-mainmenu-more {
    --core-more-item-border: blue;
    --spacer-background: blue;
}
</syntaxhighlight>


<code css>
=== Login page ===
ion-app.app-root core-course-format .core-format-progress-list .core-course-thumb {
    display: block;
}</code>


=== Moodle Classic (Ionic 1) ===
You can personalise some colors in the Login page, but keep in mind that this only includes the credentials page (the one after you select the site).
{{Moodle Mobile Classic}}


Sites using Moodle version 3.0 or lesser, should use Moodle Classic app.
<syntaxhighlight lang="css">
body {
    --core-login-background: red;
    --core-login-text-color: blue;
    --core-login-input-background: green;
    --core-login-input-color: yellow;
}
</syntaxhighlight>


Webapp to test classic app:  https://prototype.moodle.net/mobile/webapp/
=== Calendar page ===


Note: Current Moodle Desktop is based on this app, soon it will be updated to use the same code (using Ionic 3).
<syntaxhighlight lang="css">
body {
    --addon-calendar-event-category-color: purple;
    --addon-calendar-event-course-color: red;
    --addon-calendar-event-group-color: yellow;
    --addon-calendar-event-user-color: blue;
    --addon-calendar-event-site-color: green;
    --addon-calendar-today-border-color: orange;
    --addon-calendar-border-color: gray;
}
</syntaxhighlight>


You can check Ionic version 1 documentation for more info: https://ionicframework.com/docs/v1/
=== Messages page ===


== How remote themes work ==
<syntaxhighlight lang="css">
# When you enter a site in the app it checks if there's any file configured on mobilecssurl administration field on the site.
body {
# The app downloads and load the file.
    --addon-messages-message-bg: white;
## If the separator /* 3.5 styles */ is found it will load the css before or after depending on the version of the app you are running.
    --addon-messages-message-activated-bg: gray-light;
## If the separator is not found, it will load the whole css.
    --addon-messages-message-note-text: gray-dark;
# CSS selectors that contains the platform name (ios, md or wp) will only be used depending on the platform. If you want to apply it to every platform, add the three selectors.
    --addon-messages-message-mine-bg: gray-light;
## ios is for all apple platforms: including iPhone, iPad and macOS desktop app.
    --addon-messages-message-mine-activated-bg: gray;
## md is for all material design platform: including Android phones and tablets, Chrome OS and Linux desktop app.
    --addon-messages-discussion-badge: orange;
## wp is for all windows platforms: including Windows phone and Windows Store app.
    --addon-messages-discussion-badge-text: white;
## Example:
    --core-send-message-input-background: gray-light;
<code css>
    --core-send-message-input-color: black;
.toolbar-background-ios,
.toolbar-background-md,
.toolbar-background-wp {
  background: #5069A1;
}
}
</code>
</syntaxhighlight>


== Updating your theme in the app ==
=== Showing course summary image on course page ===
 
By default, course summary images are hidden to reduce scrolling when entering a course. If you want to change this behaviour, you can include the following CSS in your Remote Theme:
 
<syntaxhighlight lang="css">
ion-app core-course-format .core-format-progress-list .core-course-thumb {
    display: block !important;
}
</syntaxhighlight>


You might see that, after editing your CSS file, the changes aren't reflected in the Mobile or Desktop app. The app only receives the URL of the CSS file, it doesn't receive its timestamp, so the only way it can tell if the CSS file has changed is if the URL changes. This means that the app will only update the file if the URL has changed.
== Updating your theme after release ==


To force a download of the file you can add a hash to the URL to indicate the version of the file. So if your CSS url is like:
Once you have configured your theme, some users may already have downloaded previous styles and they will be cached.


https://mysite.com/mobile/mobiletheme.css
If you are updating the styles and you want users to get the latest version, you can change the url of the theme file. This doesn't mean that you need to change the name of the file itself, you can just add some query parameters that will be irrelevant when the file is downloaded:


Then you can add the hash to the end of it with the version number:
<syntaxhighlight lang="text">https://mysite.com/mobile/mobiletheme.css?version=1</syntaxhighlight>


https://mysite.com/mobile/mobiletheme.css#1
Every time you make some changes in your theme and you want the file to be re-downloaded in the app, just increase this number.


Every time you make some changes in the CSS and you want the file to be re-downloaded in the app, just increase this number.
== Difference between Remote Themes and Branded Apps ==


== Difference between remote themes and Branded apps ==
Remote Theme styles can be tricky to modify. There are lots of CSS rules and some of them can change between versions. Using your own Branded App, you will have better integrations because you can also use Sass variables to change colors and styles. Additionally, you will get your custom application icon and the theming will cover the entire application, not just pages using your site.
Remote theme styles can be tricky to modify. There are lots of css rules and some of them can change between versions. Using your own branded mobile app will have better style integrations because they use SaSS variables to change all the colors or styles. You can find more info on the [https://moodle.com/branded-app Branded App] page. Additionally, you will get your icon placed on all the apps stores and a fixed URL site.


You can play with that use the app variables, use sass to compile new css and use it as you personailzation.
You can find more info on the [https://moodle.com/branded-app Branded Apps] page.
{{Moodle Mobile}}

Latest revision as of 13:03, 14 July 2022

Important:

This content of this page has been updated and migrated to the new Moodle Developer Resources. The information contained on the page should no longer be seen up-to-date.

Why not view this page on the new site and help us to migrate more content to the new site!


How do Remote Themes work?

When you enter a site, it downloads any file configured on the mobilecssurl administration field and injects the styles in the app. Every time you change between sites, each style will be enabled or disabled appropriately.

The styles will remain enabled in the login page, but any other page that is not related with a specific site will use the default styles. For example, pages to add or remove sites cannot be customised with Remote Themes.

How can you create your own theme?

First of all, Remote Themes are only available for sites that purchased a Premium subscription for the Moodle App. You can check the different plans in the Apps Portal. If you want, you can follow the instructions in this document without purchasing a subscription and it will work in your development environment.

In order to create your own theme, we recommend that you use the app from master.apps.moodledemo.net and check the styles using the browser inspector. You can use any Chromium-based browser, but you should launch it with some special arguments. You can read more about that in the Using the Moodle App in a browser page. If you need to test a different version of the app, you can also use integration.apps.moodledemo.net for the latest development version or the Docker images for anything more specific.

Once you have everything ready, you can configure your theme by going to "Site administration > Mobile app > Mobile appearance" in your site and setting the mobilecssurl field to a url pointing to a CSS file. This file can be placed inside your Moodle installation in your custom theme, inside a local plugin, or hosted elsewhere.

You can get started with the following example, and you should see the background of the top bar change to red once you log into the app:

body {
    --core-header-toolbar-background: red;
}

Applying theme changes during development

For performance reasons, the app caches the styles after you log in for the first time. So if you make any changes, you won't see them unless you log out and log in again. However, there is a faster way to update them. You can also open the Preferences page in the app and click on the "Synchronise now" button. This will download the files again, and you can use this method to iterate on your styles while you make the theme.

The file can also be cached by the browser, so when you do this make sure to disable network cache as well.

Knowing what to style

Depending on how much you want to customise the UI, you'll need to do different things.

The application defines some CSS variables that can help you customise basic styles, like the one we used in our example above to change the background color of the header toolbar. You can find these variables in the source code, the main ones are defined within theme.light.scss and theme.dark.scss, and you can find others within component styles.

If you need anything more specific, the application is built using the Ionic Framework, so reading their documentation can help you understand how the UI works and which components are available. We have some custom components that you won't find listed on their documentation, but most of them built on top of Ionic's.

Finally, if you need to style something even more specific, you can always browse the source code to see how a specific page is built. You can also use the Elements Panel of your browser to inspect styles and debug anything that isn't working as you'd expect. Depending what you are trying to do, remember that this is only a development environment and it may not work correctly in a native device. If you are doing anything complicated, make sure to double check using a real device to see that everything looks good.

Notice that you will often need to use !important if you're overriding component styles directly, without using any variables. That's because the default styles are usually scoped to the Angular component, and you won't be able to provide more specificity in your selectors.

Working with colors

The main color of the app is Moodle Orange, but you can change it by using the --brand-color variable. Other than the overall brand color, there are also some specific variables for other colors.

Basic colors

These are the variables used to define the basic color palette used throughout the app:

  • --white and --black.
  • --gray, --gray-light, --gray-lighter, --gray-dark and --gray-darker.
  • --red, --red-light and --red-dark.
  • --green, --green-light and --green-dark.
  • --blue, --blue-light and --blue-dark.
  • --yellow, --yellow-light and --yellow-dark.
  • --purple and --turquoise (these don't define any variants).

Semantic colors

The basic colors are not used directly too often. Instead, the following semantic colors are used:

  • --primary (derived from --brand-color).
  • --danger (derived from --red).
  • --warning (derived from --yellow).
  • --success (derived from --green).
  • --info (derived from --blue).
  • --light (derived from --gray-lighter).
  • --medium (derived from --gray-light).
  • --dark (derived from --black).


Each of these also define other variants: rgb, contrast, contrast-rgb, shade and tint. If you want to modify any of these, it won't suffice with changing the base color they are derived from, because there are limitations and you'll have to override each variant manually.

For example, if you want to override the primary color, you'll need to override the following variables:

body {
    --ion-color-primary: #006600;

    /* RGB list of the color */
    --ion-color-primary-rgb: 0,102,0;

    /* Black or white, depending on which color gives more contrast */
    --ion-color-primary-contrast: #ffffff;

    /* RGB version of the contrast color */
    --ion-color-primary-contrast-rgb: 255,255,255;

    /* Slightly darker color. (mix 12% of black) */
    --ion-color-primary-shade: #005a00;

    /* Slightly lighter color. (mix 10% of white) */
    --ion-color-primary-tint: #1a751a;
}

Specific colors

Other than the basic and semantic colors, other components and pages define their own variables that you can override. You can look at the source code to find more, but these are some of the most relevant:

body {
    /* Page background */
    --background-color: white;
    --ion-background-color-rgb: 255, 255, 255;

    /* Main text color */
    --text-color: black;
    --ion-text-color-rgb: 0, 0, 0;

    /* Text used in categories and secondary content */
    --subdued-text-color: gray;

    /* Links text */
    --core-link-color: blue;
}

Targeting different environments

The html and body elements contain classes that indicate the environment the app is running on.

Platform

The html element indicates which platform the app is running on. For example, you can specify styles that will only apply to iOS by prepending them with html.ios, or html.md for Android:

/* Red toolbar in iOS */
html.ios body {
    --core-header-toolbar-background: red;
}

/* Green toolbar in Android */
html.md body {
    --core-header-toolbar-background: green;
}

Moodle App and Moodle site versions

The body element indicates the versions of the app and the Moodle site, so you can restrict CSS rules to a specific version by prepending one of these classes to the selector. For example, when accessing a 3.11.2 site using the 3.9.5 app the following classes will be present in the body:

  • version-3
  • version-3-11
  • version-3-11-2
  • moodleapp-3
  • moodleapp-3-9
  • moodleapp-3-9-5


And here's how to use them:

/* Red toolbar for Moodle App version 3.9.X */
body.moodleapp-3-9 {
    --core-header-toolbar-background: red;
}

/* Green toolbar for all other versions */
body {
    --core-header-toolbar-background: green;
}

Application theme

The application uses a light theme by default, but it adds the dark class to the body element when it is using a dark theme:

/* Red toolbar for the Light Theme */
body {
    --core-header-toolbar-background: red;
}

/* Green toolbar for the Dark Theme */
body.dark {
    --core-header-toolbar-background: green;
}

Bear in mind that you can disable Dark Mode for all your users following the guide for admins (Disabled features).

Combining classes

Of course, you can combine any of these classes to create more granular styles.

Let's say you want to have a red toolbar only in iOS, with the Dark Theme, for a Moodle site running 3.11.X:

html.ios body.version-3-11.dark {
    --core-header-toolbar-background: red;
}

Styling the Shadow DOM

Ionic is a set of web components, and uses the Shadow DOM to encapsulate them and make them more opaque to developers and users (hiding markup structure, style, and behavior), thus avoiding conflicts with existing rules.

This makes it more difficult to personalise and change some parts of those components. However you can check the official Ionic documentation to see which parts are customisable.

For example, if you look at the documentation for an ion-button, you can style it this way:

/* Disable text transformations */
ion-button::part(native) {
    text-transform: none;
}

/* Use a red background by default */
ion-button {
    --background: red;
}

/* Use a yellow background for buttons with the "my-custom-class" class */
ion-button.my-custom-class {
    --background: yellow;
}

You can learn more about the Shadow DOM in the following resources:

Supporting older versions of the app

If you need to support different versions of the app, or you're upgrading your theme from an older version, you should read the Moodle App Remote Themes Upgrade Guide.

Common customisations

In this section you will find a list of some common customisations you may want to add to your Remote Theme.

Header toolbar

The header toolbar has a bottom border that you can disable or customise, along with other parts:

/* Background */
ion-header ion-toolbar {
    --core-header-toolbar-background: red;
}

/* Bottom border */
ion-header ion-toolbar {
    --core-header-toolbar-border-width: 2px; /* Use 0 to disable it */
    --core-header-toolbar-border-color: green;
}

/* Text and buttons */
ion-header ion-toolbar {
    --core-header-toolbar-color: blue;
}

ion-header ion-toolbar.in-toolbar h1,
ion-header ion-toolbar.in-toolbar h2 {
    font-weight: normal;
}

Bottom tab bar (main menu)

ion-tab-bar.mainmenu-tabs {
    /* Background */
    --core-bottom-tabs-background: red;
    --core-bottom-tabs-background-selected: transparent;

    /* Tab icons */
    --core-bottom-tabs-color: blue;

    /* Selected tab icon */
    --core-bottom-tabs-color-selected: green;

    /* Badges */
    --core-bottom-tabs-badge-text-color: black;
    --core-bottom-tabs-badge-color: white;
}

Top tabs

core-tabs, core-tabs-outlet {
    /* Background */
    --core-tabs-background: red;

    /* Tab */
    --core-tab-background: red;
    --core-tab-color: white;

    /* Selected tab */
    --core-tab-color-active: blue;
    --core-tab-border-color-active: blue;
    --core-tab-font-weight-active: bold;
}

Items

body {
    /* Background */
    --ion-item-background: green;

    /* Divider */
    --item-divider-background: red;
    --item-divider-color: blue;

    /* Empty Divider */
    --spacer-background: yellow;
}

Progress bar

core-progress-bar {
    --core-progressbar-height: 4px;
    --core-progressbar-color: red;
    --core-progressbar-text-color: green;
    --core-progressbar-background: blue;
}

More page

/* Icons */
page-core-mainmenu-more {
    --core-more-icon: red;
}

/* Target a specific icon */
page-core-mainmenu-more .addon-privatefiles-handler ion-icon {
    color: green !important;
}

/* Items */
page-core-mainmenu-more {
    --core-more-item-border: blue;
    --spacer-background: blue;
}

Login page

You can personalise some colors in the Login page, but keep in mind that this only includes the credentials page (the one after you select the site).

body {
    --core-login-background: red;
    --core-login-text-color: blue;
    --core-login-input-background: green;
    --core-login-input-color: yellow;
}

Calendar page

body {
    --addon-calendar-event-category-color: purple;
    --addon-calendar-event-course-color: red;
    --addon-calendar-event-group-color: yellow;
    --addon-calendar-event-user-color: blue;
    --addon-calendar-event-site-color: green;
    --addon-calendar-today-border-color: orange;
    --addon-calendar-border-color: gray;
}

Messages page

body {
    --addon-messages-message-bg: white;
    --addon-messages-message-activated-bg: gray-light;
    --addon-messages-message-note-text: gray-dark;
    --addon-messages-message-mine-bg: gray-light;
    --addon-messages-message-mine-activated-bg: gray;
    --addon-messages-discussion-badge: orange;
    --addon-messages-discussion-badge-text: white;
    --core-send-message-input-background: gray-light;
    --core-send-message-input-color: black;
}

Showing course summary image on course page

By default, course summary images are hidden to reduce scrolling when entering a course. If you want to change this behaviour, you can include the following CSS in your Remote Theme:

ion-app core-course-format .core-format-progress-list .core-course-thumb {
    display: block !important;
}

Updating your theme after release

Once you have configured your theme, some users may already have downloaded previous styles and they will be cached.

If you are updating the styles and you want users to get the latest version, you can change the url of the theme file. This doesn't mean that you need to change the name of the file itself, you can just add some query parameters that will be irrelevant when the file is downloaded:

https://mysite.com/mobile/mobiletheme.css?version=1

Every time you make some changes in your theme and you want the file to be re-downloaded in the app, just increase this number.

Difference between Remote Themes and Branded Apps

Remote Theme styles can be tricky to modify. There are lots of CSS rules and some of them can change between versions. Using your own Branded App, you will have better integrations because you can also use Sass variables to change colors and styles. Additionally, you will get your custom application icon and the theming will cover the entire application, not just pages using your site.

You can find more info on the Branded Apps page.