Backgrounds and Foregrounds

This lesson introduces the concept of backgrounds and foregrounds in our theming platform.

We'll cover the following

Backgrounds #

Most apps have some kind of main background color. By default, that’s white in the browser. Lots of apps choose to select a grey color so that cards can be displayed on top of it. This makes for a good aesthetic view.

Let’s have a look at the following page:

This color is what we call the main background, --bg-main, of the app.

Foregrounds #

To put it simply, a foreground is also a background color, unlike some UI frameworks that call text colors a “foreground”. We call it such because those colors are used in the foreground of the app, for example in cards.

In the following picture, the cards use the main foreground color (white in this case), and behind them is the main background color (grey).

Let’s focus on a single card for a second:

The arrows point to elements with a darker foreground to contrast them a bit. This is common, but we won’t introduce another name for these, because this is simply another foreground color. That’s why we’ll define multiple foreground colors in rising levels. Each level is a darker color than the one before it, i.e., each level darkens the main foreground color even more. In the app we’re taking these screenshots from, it appears we only need 2 foreground colors: white and the slightly grey color.

The main foreground color is always called --fg-0 (white), so we’ll assign --fg-1 to the grey color.

In a dark theme:

The variables for foregrounds follow the same pattern but using dark colors. So when developing our app, we only worry about what level we want to use, and then we can be sure our design will be pretty no matter the theme.

In other apps, we might need more levels and that’s fine. Using our theming platform, we should be able to customize how many we want.

Real-world example #

Let’s take an example from discord, where we can see how we’ll need at least 3 levels:

This shows how easy consuming these variables can become.

Get hands-on with 1000+ tech skills courses.