Changing Colors on a Modern Site

A few months ago, Microsoft pushed out some new theming options for Modern sites. Now, if you use one of the Modern site templates (Modern team or Modern communication), going to the gear and selecting “Change the look” will open up a panel that allows you to select from several color schemes. (In this screenshot, you can see our PixelMill custom theme available at the top.)
Theme picker panel

Two options for customizing Modern sites

With this Microsoft update, we now have two options for customizing the colors of a Modern site:

  1. Modern themes: Tenant admins can add custom color schemes on the tenant level and make them available to Modern site owners in the side panel. Requirements: Be a tenant-level admin and use PnP-Powershell (devs can also use CSOM or REST).
  2. Classic themes: Modern site owners can create an .spcolor file and apply them on the site level with PnP-Powershell. Requirements: Be a site owner and use PnP-Powershell.

There are some differences between what colors you have control over.

  • Modern themes give you options to change three main colors — specifically, the “primary” color for buttons, links, and main accents, the “body background color” for overall backgrounds, and the “body text color” for text. Less obviously, you can also change their lighter/darker color variations with other colors for a multicolored effect, so it’s possible to set more than three colors if you take the time to figure out where the other colors are being applied. Laura Kokkarinen has an amazing post where she’s done just that.
  • Classic themes only allow for customizing three colors on modern pages, and then normal classic theme rules take over on the classic pages such as the Site Settings page. You cannot change the font color, only the accent color and two page background-related colors. In the spcolor file, these are ContentAccent1 (for the primary color), BackgroundOverlay (for the main page background color), and unintuitively, PageBackground (for certain content sections).

Take a look at the diagrams below to see how this works out in reality:

Contrasting modern vs. classic theme on a Modern Communication Site home page

The home page of a Modern Communication site doesn’t look too different when comparing classic vs. modern themes. However, notice that the “page background” appears in the search box for a classic theme, and the classic theme does not allow for a custom font color but defaults to the out-of-the-box dark grey.

Contrast modern vs classic theming on the Site Contents page

The Site Contents page starts to show more of the differences between how colors are applied in classic and modern themes. 

Contrast classic vs modern theming on Site Settings page

The Site settings page, which is a “classic” page, shows more subtle differences because the full range of classic theme colors is applied. (I used random colors in the classic theme to highlight differences.) You can see that the top ribbon picks up a different color from the classic theme, that the SharePoint logo uses a different color, and that text colors are different in classic-themed pages as well. If I had also applied a custom font with this theme, you would see it applied only to the classic page as well.

Getting started with Modern themes

1. Test your version of the SharePoint Online Management Shell.
First, make sure you have the latest version of the SharePoint Online Management Shell. If you aren’t sure, open Powershell and try this:

  1. In Powershell, run this:
    Connect-SPOService -Url https://yourtenant.sharepoint.com
  2. Enter your central admin credentials.
  3. Now run:
    Get-SPOHideDefaultThemes

If you do NOT get an error, but get either “true” or “false,” then you can continue. If you DO get an error, then uninstall your version of the SharePoint Online Management Shell and then download and install the latest version.
2. Customize theme colors.
Go to Microsoft’s online tool for generating Modern theme colors. Play with the sliders or enter in your own color codes for the primary, body, and text colors. Scroll down to the bottom part of the page to see how your color choices affect the UI elements.
Microsoft Modern theme generator
Highlight and copy the Powershell variables. (If you want a multi-colored theme, you won’t be able to make any additional custom changes to the colors in this interface, but you can copy the code into a text editor and make manual changes to the variables there.)
Copy Powershell variables
3. Run PnP-Powershell
In Powershell, you should already be connected to the SPO service from step 1. If you need to reconnect, run this: Connect-SPOService -Url https://yourtenant.sharepoint.com
Now, define a variable and assign the JSON to it:
$themepalette = [paste the code here]
Setting $themepalette variable in Powershell
Next, run the Add-SPOTheme commandlet:
Add-SPOTheme -Name "Your Theme Name" -Palette $themepalette -IsInverted $false
That’s it! This now adds the theme to your tenant, and you can access it from the “Change the look” panel.

Change the look

Custom theme shows in the panel
Hiding the default SharePoint themes
If you want to hide the default SharePoint themes so that site owners in your organization can only pick from your custom themes, run this command:
Set-SPOHideDefaultThemes $true
This will remove the SharePoint themes from the “Change the look” panel.
Hide Default Themes
To show them again, run the cmdlet with $false:
Set-SPOHideDefaultThemes $false
Removing your custom theme
If you want to remove one of your custom themes, run this cmdlet:
Remove-SPOTheme -Name "Your Theme Name"
“Your Theme Name” should match the theme name that you used when creating the theme.

Custom Classic themes on Modern sites

If you want to apply a Classic theme to a Modern site, you have to use PnP-Powershell. There is a lot of information out there about making composed looks for SharePoint 2013, but master pages and custom fonts currently are not relevant to Modern sites, so the only thing you really need to do is to modify the color file.
Prerequisites

1. Create your custom theme files.
If you want, download and install the SharePoint 2013 color palette tool, which may make it a little easier for you to define your theme colors. When you are done, save your .spcolor file into the deployment folder that you downloaded from Github.
Alternatively, you can use the test.spcolor file that comes with my demo — it adds garish colors for each element so that you can see exactly what is affected by the theme.
Remember that for Modern sites, only these three colors below are used, but the full palette may be used for classic pages such as the Site settings page:

  • ContentAccent1 (for the primary color)
  • BackgroundOverlay (for the main page background color)
  • PageBackground (for certain content sections).

2. Modify the provisioning template (if necessary).
If you saved your own custom .spcolor file, you will need to update the provisioning template. Open files-theme.xml and change the file name for the .spcolor file:
Provisioning template code
3. Run the deployment script in Powershell.
In Powershell, first, change directory into the deployment folder that contains the applyTheme.ps1 file from the download:
 cd "C:\yourdirectory"
Set your site owner credentials:
$Credentials = Get-Credential
Now run the applyTheme.ps1 script, replacing the URL with the URL for your Modern site:
.\applyTheme.ps1 -url "https://yourtenant.sharepoint.com/sites/yoursite" -Credentials $Credentials
The script will execute the commands for connecting to the SharePoint Online Modern site, setting the right variables for applying the theme, and applying the theme with CSOM.
If you refresh your site, you will now see the custom Classic theme applied to your Modern site
Result of applying classic theme
Note: As of this writing, while documentation seems to show that you can apply a background image along with the Classic theme, I haven’t had any luck with it. My background image was applied to body:before, but the background color then got applied to body:after so you couldn’t see the image. I’ll be sure to update this post if things change!
Questions? Comments? Please let us know what you think in the comments below.


Corrie Haffly Corrie Haffly
Senior Web Developer
Sea Otter Enthusiast
Your SharePoint Tour Guide

4 thoughts on “Changing Colors on a Modern Site

  1. Kesava September 5, 2018

    Hi, its a great article. can you pls share about how we can update the colors of the top navigation control/menu via themes in the modern communication template.

    1. Ernie Encinas October 3, 2018

      Yes I too would like to know if the top nav bar can be customized. The new themes does not change the color as in the classic theme suitebarbackground and topbarbackground code lines in spcolor files.
      Thanks,
      Ernie

    2. Corrie Haffly October 15, 2018

      Are you referring to the suite bar in O365 — the very top row with “O365” in it? You can take a look at this Office support article.

  2. Robert Burg August 13, 2019

    Great article, was very helpful.

Leave a Comment

Your email address will not be published. Required fields are marked *

Enter Code *

Filed Under

Related

On the next episode of the #PixelMillWebinars:
- Understand Viva Connections + Viva Engage and how they work together
- Learn how to prepare your Microsoft environment for these platforms
- The evolution of Yammer into Viva Engage
Register: https://hubs.ly/Q01HzQJN0

On this episode of #PnPWeekly—the podcast that discusses the latest topics on M365—our very own Microsoft RD+MVP & CPO @EricOverfield joins @vesajuvonen & @waldekm to talk Viva Goals, SharePoint Starter Kit, the future of ChatGPT, & community conferences. https://hubs.ly/Q01HnFJY0

On the next episode of the #PixelMillWebinars:
- Understand Viva Connections + Viva Engage & how they work together
- Learn how to properly prepare your Microsoft environment for these two platforms
- The evolution of Yammer into Viva Engage

Register: https://hubs.ly/Q01FJ9Hk0

On the next #PixelMillWebinar:
-Discover what AI opportunities are at your fingertips with Microsoft 365
-We'll deliver AI-driven takeaways that will help you and your team increase productivity, bring visibility to employees' work, and more!

Register: https://hubs.ly/Q01D0JPs0

On the next episode of the #PixelMillWebinars:
-Discover what AI opportunities are at your fingertips with Microsoft 365
-We'll deliver AI-driven takeaways that will help you increase productivity, automate work using machine learning, and more!
Register: https://hubs.ly/Q01BVdsR0

Subscribe to PixelMill's
E-news

* indicates required

Let's Talk Digital
Workspaces Today

Get In Touch