Forum Discussion

Lee-Martin's avatar
Lee-Martin
Brass Contributor
Jan 10, 2023

Add html code to Modern Page

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?

  • 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.

    • Lee-Martin's avatar
      Lee-Martin
      Brass Contributor
      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
  • SvenSieverding's avatar
    SvenSieverding
    Bronze Contributor

    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

    • Adnan_Amin's avatar
      Adnan_Amin
      MVP
      Agree with Sven. you can enable custom scripting on the site or you can use spfx web part for the required output.

Resources