Themeable CSS for SharePoint Site

Mohammed Abed 155 Reputation points
2023-05-31T09:06:37.9166667+00:00

I am working on a SharePoint 2019 Publishing Site with custom CSS and Master Page.

I imported the CSS files regularly as any HTML page in the head:

    <link rel="stylesheet" href="assets/styles/all.min.css" />
    <link rel="stylesheet" href="assets/styles/style.css" />
    <link rel="stylesheet" href="assets/styles/bootstrap.min.css" />
    <script
      src="assets/scripts/bootstrap.bundle.min.js"
      type="text/javascript"
    ></script>

However, not all CSS rules are applied especially with the custom font I am using. I imported the font using font-face

@font-face {
  font-family: 'Cairo';
  font-style: normal;
  font-weight: 900;
  font-display: swap;
  src: url('../fonts/SLXVc1nY6HkvangtZmpQdkhzfH5lkSscSCyS4J0.woff2')
    format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+2000-206F,
    U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

* {
  margin: 0;
  padding: 0;
  font-family: 'Cairo', sans-serif;
}

The site is still reading the core.css file as it appears in the browser source tab. Adding !important also screw things up.

I have read in some articles that I need to make my CSS themeable and upload to the specific location the import it in the Master Page.

Are there any alternatives, and what is the best way for that ?

Microsoft 365 and Office SharePoint Server For business
Microsoft 365 and Office SharePoint Development
Microsoft 365 and Office SharePoint For business Windows
Microsoft 365 and Office SharePoint Server Development
{count} votes

Accepted answer
  1. Anonymous
    2023-06-01T09:46:37.94+00:00

    Hi @Mohammed Abed ,

    In SharePoint 2019, the recommended way to apply custom CSS to a Publishing Site and ensure it overrides the default styles is by creating a custom theme. Here's the approach you can follow:

    Create a custom theme:

    Go to the root site of your SharePoint Publishing Site.

    Open Site Settings.

    Under the "Look and Feel" section, click on "Change the look."

    Customize the theme using the provided options or upload a custom theme file ( and ) that includes your custom CSS and font definitions..spcolor.spfont

    Upload the custom CSS file:

    In the same "Change the look" settings page, click on "Theme" from the left navigation pane.

    Upload your custom CSS file (e.g., ) that includes the CSS rules and font-face declarations.custom.css

    Apply the custom theme to the Master Page:

    Open the Master Page in SharePoint Designer or any preferred text editor.

    Locate the  section of the Master Page.<head>

    Add the reference to the custom CSS file within the  section, like this:Make sure to adjust the URL path based on the location where you uploaded the custom CSS file.

    <link rel="stylesheet" href="/sites/YourSite/_catalogs/theme/15/YourThemeFolder/custom.css" />

    Save and publish the Master Page.

    By following this approach, SharePoint will apply the custom theme, which includes your custom CSS file, to the entire site and override the default styles. The custom font-face declarations should also be recognized and applied correctly.

    Remember to clear the browser cache to ensure the latest CSS changes are loaded when testing.

    Note: It's always recommended to make a backup of the original Master Page before making any modifications.

    I hope this helps you achieve the desired customization in SharePoint 2019!


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards

    Cheng Feng


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.