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.)
Two options for customizing Modern sites
With this Microsoft update, we now have two options for customizing the colors of a Modern site:
- 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).
- 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:
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.
The Site Contents page starts to show more of the differences between how colors are applied in classic and modern themes.
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:
- In Powershell, run this:
Connect-SPOService -Url https://yourtenant.sharepoint.com
- Enter your central admin credentials.
- Now run:
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.
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.)
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]
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.
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:
This will remove the SharePoint themes from the “Change the look” panel.
To show them again, run the cmdlet with $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.
- If you’re new to PnP-Powershell, go through the prerequisites from Get started with PnP-Powershell.
- Download our starter files from Github.
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:
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:
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
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.