Add html code to Modern Page

Brass Contributor

I've some html code (with css) that I want to add to the page

 

I've tried uploading it to Site Assets as an aspx file, but it won't let me embed it.

 

I just need to do this as a quick one off and don't have time to do a full web part.


Is there an easy way I can just add it?

4 Replies

@Lee-Martin 

"Disable Custom Scripting" is enabled per default on new sites because of security concerns. So custom ".aspx" files are always downloaded and not displayed.

 

To  disable "Disable Custom Scripting" do the following:

1) Be a SharePoint Administrator (SiteCollection Admin is not sufficient)
2) Either connect with the SharePoint Management Shell to the SharePoint admin site (https://<tenant>-admin.sharepoint.com) and execute

Set-SPOSite <SiteURL> -DenyAddAndCustomizePages 0

3) Or connect with PNP Powershell to the SharePoint admin site (https://<tenant>-admin.sharepoint.com) and execute

Set-PnPSite -Identity <SiteURL> -NoScriptSite $false

(https://learn.microsoft.com/en-us/sharepoint/allow-or-prevent-custom-script)

Best Regards,
Sven

Agree with @Sven. you can enable custom scripting on the site or you can use spfx web part for the required output.

@Lee-Martin If you are trying to embed custom HTML/CSS/JS on modern pages, you can use Modern script editor web part developed using SPFx by community members.

 

This web part code is available at: Script editor web part for modern pages built in React 


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

@ganeshsanap

Thamk you, but I don't have time to mess around with uploading webparts at the moment - I need to be able to embed the aspx page