I am looking for a solution to apply existing theme in SharePoint Modern Site using code.

2 Answers 2


The Official Documentation on Microsoft gives us a few REST calls to manage your tenant themes:

http://<site url>/_api/thememanager/AddTenantTheme
http://<site url>/_api/thememanager/RemoveTenantTheme
http://<site url>/_api/thememanager/GetTenantThemingOptions

Since add/removing themes is a tenant scoped feature, you must have the clearance to manage them (Tenant Admin).

If you wish to apply a classic theme to a modern site, here is a link that gives a script to use.

To select the correct theme in a site, this is a manual procedure (I haven't found an endpoint, but there may be) which is pretty simple (Cog in the ribbon > Change the look > Select your theme).

Rolling out pretty soon (announced without a release date I believe), Hub sites will automatically apply the hub theme to any site you decide to attach.

Hope this helps!


There are other methods in that thememanager toolkit that are not mentioned in the prior response. Specifically, I am referring to ApplyTheme

Here is some sample code from the MS Docs / Learning site.

function RestRequest(url,params) {
  var req = new XMLHttpRequest();
  req.onreadystatechange = function ()
    if (req.readyState != 4) // Loaded
  // Prepend web URL to url and remove duplicated slashes.
  var webBasedUrl = (_spPageContextInfo.webServerRelativeUrl + "//" + url).replace(/\/{2,}/,"/");
  req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
  req.setRequestHeader("ACCEPT", "application/json; odata.metadata=minimal");
  req.setRequestHeader("x-requestdigest", _spPageContextInfo.formDigestValue);
  req.send(params ? JSON.stringify(params) : void 0);

var pal = {
    "palette" : {
        "themePrimary": "#1BF242",
        "themeLighterAlt": "#0d0b00",
        "themeLighter": "#0b35bc",
        "themeLight": "#322d00",
        "themeTertiary": "#6a5f00",
       "themeSecondary": "#1B22F2",
        "themeDarkAlt": "#ffe817",
        "themeDark": "#ffed4b",
        "themeDarker": "#fff171",
        "neutralLighterAlt": "#252525",
        "neutralLighter": "#282828",
        "neutralLight": "#313131",
        "neutralQuaternaryAlt": "#3f3f3f",
        "neutralQuaternary": "#484848",
        "neutralTertiaryAlt": "#4f4f4f",
        "neutralTertiary": "#c8c8c8",
        "neutralSecondaryAlt": "#d0d0d0",
        "neutralSecondary": "#dadada",
        "neutralPrimary": "#ffffff",
        "neutralDark": "#eaeaea",
        "black": "#f8f8f8",
        "white": "#1f1f1f",
        "primaryBackground": "#1f1f1f",
        "primaryText": "#ffffff",
        "error": "#ff5f5f"
RestRequest("/_api/thememanager/ApplyTheme", {name:"Sounders Rave Green", themeJson: JSON.stringify(pal)});

Full Article: https://learn.microsoft.com/en-us/sharepoint/dev/declarative-customization/site-theming/sharepoint-site-theming-rest-api

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.