Guide to Creating Themes


This page explains, step by step, how to create a new theme for JOEL: a colour scheme for the whole website that users can get from the gacha and choose in their profile.

Creating a theme requires access to the server (to edit and compile the styles) and being an administrator (to create the achievement). If you are a student and have an idea for a theme, you can prepare the colours and pass them on to your teachers.

How a theme works

A theme is three pieces that must have exactly the same name, for example theme-mar:

  1. A colour block in the stylesheet resources/base.scss, in the form :root[data-theme=theme-mar] { ... }. Inside there are about 30 colour variables (--global-text, --widget_black...), and each part of the website takes its colour from one of these variables.
  2. An achievement of category theme called theme-mar. This is what appears in the gacha.
  3. The user's choice: when someone who has the achievement picks it in Edit profile → Web theme, their profile stores theme-mar and every page puts data-theme="theme-mar" on the <html> tag. From then on, the browser uses the colours from the block in step 1 instead of the default ones.

If a variable doesn't appear in the theme block, the one from the default theme is used (the usual blue and white). If the name doesn't match exactly between the CSS and the achievement, the theme won't do anything.

Step 1: choose the name

It must start with theme- and may only contain unaccented letters, numbers and hyphens: theme-mar, theme-retro80. Check that it doesn't already exist: the current themes are theme-dark, theme-candy, theme-wmt, theme-atomdark, theme-DTpurple, theme-BUBIMan, theme-olddark and theme-oldcandy.

Step 2: write the colours

Open resources/base.scss, copy the whole block of a theme that resembles the one you want (a dark one like theme-dark or a light one like theme-candy), paste it right after, rename it and start changing the colours.

These are the variables and where they are used:

Text

  • --text-black: the normal text of the whole page (body, tables, user links...). It is the most important variable.
  • --global-text: page and section titles (h1, h2...) and test case text.
  • --text-white: text on coloured backgrounds: buttons, table headers, notices and the contest information bar.
  • --global-gray: footer text.

Links

  • --global-link, --global-link-hover, --global-link-active: colour of links, when hovering over them and when clicking them.
  • --title_blue, --title_hover: blog post titles and contest names on the home page.

Backgrounds

  • --background-white: background of the page's central content, of active tabs and of comments.
  • --background_light_gray: background of the page (outside the content), of forms and of code blocks.
  • --background_gray: sortable table headers, the footer and the problem list row under the mouse.
  • --background_table_pyjama: the even rows of striped tables.
  • --background_input: text boxes and text areas.
  • --background_black, --background_dark_gray: page header and contest information bar.

Top menu bar

  • --widget_black: background of the menu bar and its drop-downs.
  • --nav-text: text of the menu, the drop-downs and the user menu ("Hello, ..."). If you don't set it, --text-white is used.
  • --nav-active-bg, --nav-active-text: background and text of the section you're currently in.
  • --text-nav, --nav-hover-bg: text and background of a menu item when you hover over it.
  • --highlight_blue: the coloured stripe of the drop-downs and some details (problem of the day, user links).

Buttons and borders

  • --button_blue: button background.
  • --border_gray, --border_black, --border_dark_gray: box borders, separator lines and table borders.
  • --announcement_red: background of important notices.

There are a few more variables in the block (--global-white, --global-black, --button_grad) that are hardly used today. Leave them with a reasonable value.

A minimal example:

:root[data-theme=theme-mar] {
    --text-black: #e6f1ff;
    --global-text: #ffffff;
    --background-white: #0b2545;
    --background_light_gray: #13315c;
    --widget_black: #134074;
    --nav-text: #ffffff;
    --global-link: #8ecae6;
    /* ...and the rest of the variables */
}

Step 3: check that it's readable

This is the most common mistake. Every text must have enough contrast with its background: at least 4.5 to 1. You can check it with any online contrast checker (for example, WebAIM's: enter the text colour and the background colour). The pairs you must always check:

  • --text-black on --background-white and on --background_light_gray (normal text and code).
  • --global-text on --background-white (titles).
  • --nav-text on --widget_black (menu and drop-downs).
  • --nav-active-text on --nav-active-bg, and --text-nav on --nav-hover-bg (menu).
  • --text-white on --button_blue (buttons).
  • --global-link on --background-white (links).

Mistakes that have already happened in existing themes:

  • Forgetting the #: --global-white: a2d2ff; is not a valid colour and gets lost. It must be #a2d2ff.
  • Made-up colours: #orange doesn't exist. Either orange, or a code like #ffa500.
  • Dark text on a dark background in the menu: if the menu background (--widget_black) is dark, the menu text (--nav-text) must be light, even if --text-white is dark because your buttons are light.

Step 4: compile and publish the styles

On the server, from the JOEL folder:

./make_style.sh
cp resources/style.css /tmp/static/style.css

make_style.sh converts the .scss files into the .css files the website uses. Copying to /tmp/static (the static files folder served by nginx) publishes it. There's no need to restart anything: the website picks up the new file within a few seconds. If you have also changed other style files, copy them too (or use python manage.py collectstatic).

Before compiling, check that the result only contains your changes: if someone else has left half-finished style changes, they would be published too.

Step 5: try it without owning it

Once the styles are published, you don't need the achievement to see how the theme looks. On any JOEL page, open the browser console (F12, Console tab) and type:

document.documentElement.dataset.theme = 'theme-mar'

The page switches to the theme's colours instantly (only for you and until you reload). Review at least: the home page, the problem list, a statement with code, a submission page, a leaderboard, the drop-down menu and the user menu, the buttons, a form and the gacha.

Step 6: create the achievement

In the administration: Achievements → Add.

  • Achievement name: exactly the theme name (theme-mar). It's what will be shown in the profile drop-down.
  • Achievement category: theme. Only administrators can choose it; achievement creators can only make stickers and icons.
  • Achievement quality: the current themes are legendary.
  • Achievement image: a screenshot of the website with the theme applied, so people can see what they got.
  • Achievement description: a sentence about the theme.

From then on it can come up in the gacha. To really test it with your own user, you can give yourself the achievement from the administration and pick it in Edit profile → Web theme.

Quick summary

  1. Name: theme-algo, the same everywhere.
  2. Block :root[data-theme=theme-algo] { ... } in resources/base.scss, copying an existing theme.
  3. Contrast of at least 4.5 to 1 for every text and background pair.
  4. ./make_style.sh and copy resources/style.css to /tmp/static/.
  5. Try it with document.documentElement.dataset.theme = 'theme-algo'.
  6. Achievement with the same name and category theme.