DEV Community

Cover image for Create and add a custom color theme to SharePoint Online using PnP powershell
Eli H. Schei
Eli H. Schei

Posted on • Updated on • Originally published at elischei.com

Create and add a custom color theme to SharePoint Online using PnP powershell

Prerequesites:
You need to have the PnP Powershell module installed to use the pnp powershell commands as described in this article.

Introduction

Most comapnies want to use their own brandcolors in SharePoint Online to make it look nice and familiar to their employees. Because of this custom color themes is a topic every MS365 developer should feel comfortable with. Also, it is quite straightforward.

In this blogpost I will show you how you can create a custom color palette, make the theme available tenant-wide, and how to set the theme on specific sites, all by using PNP-powershell.

Note, to change the color of the suitebar/navigationbar (the top bar that follows you around MS365 not just in SharePoint Online) you can do so in the admin-center. Go to Admin –> Settings –> Org Settings –> Organization profile and select Custom Themes.

Before you start you should open the CLI (command line interface) and connect to your tenant admin site. You do this by adding a “-admin” at the end of your domain. I also use the -Interactive parameter since I have MFA (multi factor authentication) enabled on my tenant.

//Log in to your tenant
Connect-PnPOnline "https://yourtenant-admin.sharepoint.com" -Interactive

Create a custom color palette

If you are not sure if your tenant allready have a custom theme available you can use the command Get-PnPTenantTheme to get a list of available themes.
Alt Text

If this command does not return anything, there are no custom themes in your tenant. Out of the box SharePoint themes will not show up in this list.

If there are multiple themes, like in the picture above, you can specify which theme you want by adding the theme name to your command. Add the -asJSon flag to get the color palette as a json-string you can copy.

//Get a specific theme by name, and as JSON
Get-PnPTenantTheme "Elis main theme" -asJson

Use a tool to create your color palette

If you dont have a custom theme to edit, or you want some visual help when creating your color palette you can use a tool like the Fluent UI Theme designer. I especially like this tool because it also tells you if your chosen colors keeps the wcag accessibility standards.

This article in the Microsoft docs gives you a nice overview over where the different color-variables is typicalle being used in SharePoint.

Make the new theme available on your tenant

When you have created the palette its time to make it available in your tenant. Create a variable that contains the color-palette. Use this variable when you run the Add-PnPTenantTheme command as shown below.

$color_palette = @{
         "themePrimary" = "#874070";
         "themeLighterAlt" = "#faf5f9";
         "themeLighter" = "#ecd8e5";
         "themeLight" = "#dbb8d0";
      "themeTertiary" = "#b77da5";
      "themeSecondary" = "#96507f";
      "themeDarkAlt" = "#7a3965";
      "themeDark" = "#673055";
      "themeDarker" = "#4c243f";
      "neutralLighterAlt" = "#faf9f8";
      "neutralLighter" = "#f3f2f1";
      "neutralLight" = "#edebe9";
      "neutralQuaternaryAlt" = "#e1dfdd";
      "neutralQuaternary" = "#d0d0d0";
      "neutralTertiaryAlt" = "#c8c6c4";
      "neutralTertiary" = "#a19f9d";
      "neutralSecondary" = "#605e5c";
      "neutralPrimaryAlt" = "#3b3a39";
      "neutralPrimary" = "#323130";
      "neutralDark" = "#201f1e";
      "black" = "#000000";
      "white" = "#ffffff";
}

Add-PnPTenantTheme -Identity "Elis Main Theme" -Palette $color_palette -IsInverted $false
Enter fullscreen mode Exit fullscreen mode

Add the theme to a site

If you run “Get-PnPTenantTheme” again you can see your theme on the list. You can also find it through the UI. Go to a SharePoint site and select “Change the look” / “Themes”, and you will see your new theme in the list.
Alt Text

So lets add the theme to a site using powershell. You do this by using the Set-PnPWebTheme command and adding the name of the theme, and the webUrl of the site as parameters.

Set-PnPWebTheme -Theme "Elis Main Theme" -WebUrl "https://yourtenant.sharepoint.com/sites/ThemeTestSite"

Summary

In this blogpost I showed you how to create and add a custom color theme to your SharePoint Online tenant using PnP powershell. I hope you found this usefull.

Top comments (0)