Dear Revevol Transformation,
Thank you for posting your query in our community.
I understand your concern and would like to convey that In classic pages, You can add HTML code to the SharePoint Online page using either the content editor web part or the script editor web part (or using Embed code).However, in Modern SharePoint Online pages, both web parts are unavailable. Adding HTML code to a SharePoint Online Modern Page is a great way to enhance the functionality or design of your site. With the ability to add custom code, you can create unique and engaging user experiences that are tailored to your specific needs. In this guide, we will walk you through the steps of adding HTML code to a SharePoint Online Modern Page, using the Embed web part.
So, how to display HTML content on modern pages? If you want to add HTML code in SharePoint Online’s modern page, follow this trick:
- Create an HTML page, and rename its extension from .HTML to .aspx
- Upload aspx file to SharePoint Online – Upload the ASPX page and resources to the SharePoint Online Library.
- Use the “Embed” web part to display it on the Modern SharePoint Online page.
Make sure you have enabled the custom script, Enable Custom Scripts for a Site in Admin Center
How do you allow custom scripts from the Admin Center for the SharePoint Online site? Here is how:
- Sign in to the SharePoint Admin Center: https://<tenant>-admin.sharepoint.com.
- Expand “Sites” and click “Active sites” from the left navigation. Select the site from the list by clicking on the site name link.
- On the site properties panel, Click on the Settings tab. Click on the “Edit” link under “Custom Scripts”.
- Select “Allowed” settings for Custom scripts. Click on “Save” to commit your changes.
Follow the below steps to add an HTML code to modern pages:
- Open your SharePoint Online site in the web browser.
- Upload the .aspx file and its associated resources, like scripts and images, to any of your SharePoint libraries, such as “Site Assets”. Ensure any references to these images/styles/scripts are updated in the ASPX file.
- Once uploaded, navigate to the page where you would like to add HTML code and edit the page.
- Insert an “Embed” web part wherever relevant. This web part allows you to display HTML code directly into the web part. You can use this method if you want to add a small piece of code from another page. Set the Embed source address to the ASPX file you have uploaded.
- That’s all! Here is the result of HTML code in the modern page.
In summary, adding HTML code to a SharePoint Online Modern Page can be done by using the Embed web part and saving an HTML file as an ASPX. It is important to remember that custom code may potentially break the functionality of the page and should be thoroughly tested before being added to a live site.
If you have any additional questions or if you need any additional help regarding this or anything else at all - let me know, I'll be here to help you out.
And in the meantime, I hope you'll have a lovely day ahead, stay safe & take care!
Yours sincerely,