How to Embed HTML or Code in Modern SharePoint Pages
Question details
The user needs to embed custom HTML, scripts, or iframes into a modern SharePoint page after discovering that older methods are no longer supported.

- Product
- Microsoft SharePoint
- Device & OS
- not provided
- Scenario
- Attempting to embed external HTML content, custom scripts, or a SharePoint URL into a modern SharePoint site page.
- Observed behavior
- Older workarounds, such as uploading an HTML file as an ASPX page, fail because modern SharePoint restricts unsupported page types and custom scripts for security reasons.
Verify with your Microsoft 365 administrator that the external domain you want to embed is approved in your SharePoint site's HTML Field Security settings.
Use the SharePoint Embed Web Part
This is the primary and Microsoft-supported method to add HTML iframe snippets or embed URLs directly into a modern SharePoint page.
Modern SharePoint pages use an isolated, secure environment. The Embed web part allows you to display content from other sites (like YouTube, Bing maps, or internal SharePoint pages) as long as it uses standard iframe tags.
Navigate to the modern SharePoint page where you want to embed the code and click 'Edit' in the top right corner.
Hover your mouse over the page canvas until you see the circled '+' icon. Click it to open the web part menu, search for 'Embed', and select it.
In the property pane that opens on the right side of the screen, paste your HTML iframe code or secure website URL (starting with https://) into the 'Website address or embed code' box.
Review the preview generated on your page. If it looks correct, click 'Republish' or 'Save as draft' at the top of the page to apply your changes.

Configure HTML Field Security Settings
If the Embed web part displays an error stating the content cannot be embedded, the site domain must be explicitly allowed by an administrator.
Develop a Custom SPFx Web Part
If you must run custom JavaScript or complex HTML structures that standard web parts block, developers must use the SharePoint Framework (SPFx).
Boost Your Team's Productivity with WPS Office
While SharePoint serves as your platform for site creation and intranet management, WPS Office is an excellent lightweight, high-performance alternative to Microsoft Office for creating, editing, and managing your actual documents. It offers premium features for a fraction of the cost, ensuring your team stays productive.
- 1. Download the software: Visit the official WPS Office website and download the installer tailored for your operating system.
- 2. Install WPS Office: Run the setup file and follow the quick on-screen instructions to install the suite on your device.
- 3. Edit your documents: Open WPS Office to immediately start creating, editing, and converting files with perfect compatibility.

Frequently Asked Questions
Why does my HTML file uploaded as ASPX no longer work in SharePoint?
Modern SharePoint environments strictly regulate custom script executions and block unsupported page types to prevent malicious code injections and cross-site scripting (XSS). As a result, legacy workarounds like renaming HTML to ASPX are permanently disabled on modern sites.
Can I use `<script>` tags in the SharePoint Embed web part?
No, the standard Embed web part in modern SharePoint automatically strips out `<script>` tags to comply with Microsoft's security protocols. To execute custom JavaScript, your organization must develop and deploy a custom SharePoint Framework (SPFx) web part.
Why am I getting an 'embedding is not supported' error when using an iframe?
This error typically appears when the external website's domain is not approved in your SharePoint site's security settings. A site administrator must navigate to 'HTML Field Security' in the site settings and explicitly add the domain to the allowed list.




