How to Customize a SharePoint Modern Page with HTML, JavaScript, or CSS
Question details
The user wants to inject custom HTML, JavaScript, or CSS into an entire SharePoint modern page instead of modifying individual SPFx web parts.
- Product
- SharePoint
- Device & OS
- not provided
- Scenario
- Customizing the appearance and behavior of a modern SharePoint page with custom code snippets.
- Observed behavior
- To successfully deploy, configure, and troubleshoot the third-party Modern Script Editor web part to run the custom scripts on the page.
Ensure you have the necessary SharePoint administrative permissions to deploy custom apps to the App Catalog and add web parts to your modern pages.
Use the Modern Script Editor Web Part
Install and use the third-party Modern Script Editor to inject custom HTML, CSS, and JavaScript into your modern page.
By default, SharePoint modern pages do not include a native script editor. The Modern Script Editor is a popular community-driven tool from the SharePoint Patterns and Practices (PnP) community that allows you to easily embed custom scripts onto these pages.
Download the Modern Script Editor app package from the official PnP GitHub repository and upload it to your SharePoint App Catalog.
Navigate to the modern page you want to customize, click 'Edit' in the top right corner, and click the '+' icon to add a new web part. Search for 'Modern Script Editor' and add it to the page.
Click the 'Edit snippet' button inside the newly added web part and paste your HTML, JavaScript, or CSS code into the editor. Save and publish the page.
Troubleshoot Modern Script Editor Issues
Resolve issues if the Modern Script Editor web part fails to load or execute your custom code.
Boost Your Productivity with WPS Office
While you manage your SharePoint sites online, use WPS Office as a lightweight, powerful, and free desktop alternative to Microsoft Office for creating and editing your documents, spreadsheets, and presentations with perfect format compatibility.
- 1. Download and Install: Download WPS Office for free from the official website and follow the simple installation prompts.
- 2. Create or Edit Documents: Open WPS Office to instantly start working on text documents, spreadsheets, or presentations in a tabbed interface.
- 3. Save and Upload to SharePoint: Save your files in standard .docx, .xlsx, or .pptx formats, then drag and drop them directly into your SharePoint document library.

Frequently Asked Questions
Is the Modern Script Editor an official Microsoft product?
No, the Modern Script Editor is a third-party open-source web part developed by the SharePoint Patterns and Practices (PnP) community. It is not officially supported by Microsoft.
Can I use standard SPFx web parts instead of the Modern Script Editor?
Yes, standard SharePoint Framework (SPFx) web parts are the officially recommended way to add custom functionality. However, the Modern Script Editor is often preferred for quick injections of HTML, CSS, or JavaScript without having to write, build, and deploy custom SPFx code from scratch.
Why is my JavaScript not executing on the modern page?
By default, SharePoint modern pages restrict custom script injection for security reasons. Ensure that your tenant allows custom scripts, that the Modern Script Editor web part is correctly deployed, and that you are using the latest version of the app.




