SharePoint Online: How to Inject Custom CSS in Modern Sites?
Requirement: Add custom CSS to mode
SharePoint Online sites.
ESPC Dublin25
CCD, DUBLIN, IRELAND, 01–04 DEC 2025
European Power Platform Conference
AVC, VIENNA, AUSTRIA, 16-19 JUNE 2025
European Microsoft Fabric Community Conference
VIENNA, AUSTRIA, 15–19 SEPT 2025
ESPC Dublin25
CCD, DUBLIN, IRELAND, 01–04 DEC 2025
European Power Platform Conference
AVC, VIENNA, AUSTRIA, 16-19 JUNE 2025
European Microsoft Fabric Community Conference
VIENNA, AUSTRIA, 15–19 SEPT 2025
Requirement: Add custom CSS to mode
SharePoint Online sites.
The Alte
ate CSS and script editor web parts are not supported in the Mode
SharePoint Online sites. However, if you want to inject a custom CSS to your SharePoint Online sites, you can use the React application customizer to inject CSS. Here are the steps at a high level:
In my case, we wanted to hide the “Export to Excel” button in all lists and libraries of a SharePoint Online site and used this CSS in my custom.css file and uploaded it to the “Style Library” folder of the site:
button[name="Export to Excel"] {
display: none;
}
Go to https://github.com/hugoabe
ier/react-application-injectcss/tree/master/assets and download the “react-application-injectcss.sppkg” file to your computer. You can also download the source code and build a new solution with your own customizations.
Once you have the SPFx package ready, you can deploy it to your app catalog to make it available on any site of your tenant.
More info on How to Deploy an App to App Catalog in SharePoint Online?
The next step is to deploy the application customizer to the site or tenant using custom action. Here is the PowerShell to deploy the application customizer:
#Parameters
$SiteUrl = "https://crescent.sharepoint.com/Sites/Marketing"
$customCSSUrl = "https://crescent.sharepoint.com/sites/Marketing/Style%20Library/custom.css"
#Connect to Site
Connect-PnPOnline $SiteUrl -Credentials (Get-Credential)
#Add Custom Action
Add-PnPCustomAction -Title "Inject CSS Application Extension" -Name "InjectCssApplicationCustomizer" -Location "ClientSideExtension.ApplicationCustomizer" `
-ClientSideComponentId "5a1fcffd-dfeb-4844-b478-1feb4325a5a7" -ClientSideComponentProperties "{""cssurl"":""$customCSSUrl""}"
#Read more: https://www.sharepointdiary.com/2020/09/sharepoint-online-inject-custom-css-to-mode
-sites.html#ixzz76Kz6Vsvd
If you want to remove the application customizer, you can do by:
#Parameters
$SiteUrl = "https://crescent.sharepoint.com/Sites/Marketing"
#Connect to Site
Connect-PnPOnline $SiteUrl -Credentials (Get-Credential)
#Remove the Custom Action
Get-PnPCustomAction | Where { $_.Name -eq "InjectCssApplicationCustomizer"} | Remove-PnPCustomAction -Force
#Read more: https://www.sharepointdiary.com/2020/09/sharepoint-online-inject-custom-css-to-mode
-sites.html#ixzz76KzF27TK
That’s all, Your custom CSS should be in action! The “Export to Excel” button is hidden through our custom CSS:
This blog is part of SharePoint Week. For more great content, click here
About the Author:
Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!
Reference:
Rajack, S. (2021). SharePoint Online: How to Inject Custom CSS in Mode
Sites? Available at: https://www.sharepointdiary.com/2020/09/sharepoint-online-inject-custom-css-to-mode
-sites.html [Accessed: September 13th 2021].
Become an ESPC Community Member today to access a wealth of SharePoint, Teams and Azure knowledge for free. New content is added daily to the online Resource Centre, across a variety of topics and formats from Microsoft MVPs and industry experts. With over 2,500 eBooks, webinars, presentations, how-to videos and blogs, there is something to suit everyone’s learning styles and career goals.