DEV Community

Georg Müller
Georg Müller

Posted on

2 2

Branding a multitenated application using CSS

A friend of mine had an interesting challenge. He wanted to have a public part of an B2B application brandable in the color of its customers and asked me how I would do it. This post describes what I told him.

The application basically is a simple form and a summary describing the data the user will submit.

Base setup in the CSS

Use CSS variables for the colors and use them consistently where you want the brands colors to be applied.

:root{
  --brand-color-1:rgb(66,153,225);
  --brand-color-2:rgb(255,255,255);
}
Enter fullscreen mode Exit fullscreen mode

I this case I created a themable button:

button {
  background-color: var(--brand-color-1);
  border-color: var(--brand-color-2);
  color: var(--brand-color-2);
  border-radius: 3.5rem;
  border-style: solid;

  padding: 6px 10px 6px 10px;
}
Enter fullscreen mode Exit fullscreen mode

Looks like this: Button with blue background

Use CSS inheritance to override the color

In CSS properties are inherited from the root element to its child elements.
In this case I would override it on body as I would like to have all elements using the overridden colors, eg like this:

<body style="--brand-color-1: #48BB78">
Enter fullscreen mode Exit fullscreen mode

Button with green background

Now you can override the color on the html using your web framework of choice.

If you are rendering on the server you should be aware of caching. You would probably like to cache by tenant and make sure you invalidate when changing the colors, but that is out of scope for this post.

If you want to play around with this solution I made a codepen:

Concluding

This is a solution by a backend developer :-). Do you know of a better solution?

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Cloudinary image

Optimize, customize, deliver, manage and analyze your images.

Remove background in all your web images at the same time, use outpainting to expand images with matching content, remove objects via open-set object detection and fill, recolor, crop, resize... Discover these and hundreds more ways to manage your web images and videos on a scale.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay