Live training: next batches coming soon. Join the waitlist:Waitlists open:Developer Training →Developer →Copilot Studio Training →Copilot Studio →

Content Editor Web Part in SharePoint Online: Add HTML, Scripts and Modern Alternatives

The Content Editor web part still adds HTML, CSS and JavaScript to a SharePoint Online page, but only on a classic wiki or web part page. Modern pages don’t have it, so you use Text, Embed, Markdown, Code snippet or an SPFx web part.

In this tutorial, we’ll add the content editor web part to a classic page, write HTML in the Source Editor, load a file from Site Assets with Content Link, fix the "missing web part" problem, and compare the modern options.

Here’s the kind of snippet you paste into its Source Editor:

<div style="background:#E8F1FB;border-left:4px solid #0F6CBD;padding:12px 16px;">
  <h3 style="margin:0;">SPGuides IT announcement</h3>
  <p>The help desk moves to the new ticket portal on Monday.</p>
  <p id="spgToday"></p>
</div>
<script>
  document.getElementById("spgToday").textContent =
    "Last checked: " + new Date().toLocaleDateString("en-US");
</script>

It renders a blue announcement box, and the script writes today’s date, such as 10/26/2026.

What is the Content Editor web part in SharePoint?

It’s a classic Media and Content web part that holds rich text, Source Editor HTML, or a Content Link to a file. New to classic pages? Read SharePoint classic vs modern experiences first.

It doesn’t accept an HTML <form> element and isn’t built to show another website; the Page Viewer web part does that. More how-tos sit in the SharePoint tutorials hub.

How to add a Content Editor web part to a classic page

My demo is a classic team site, /sites/SPGuidesClassic, with custom script allowed. Open the wiki page (here SitePages/Team-Notes.aspx) and select PAGE > Edit:

PAGE tab with the Edit button on the Team Notes classic wiki page

Click where the web part should go, select INSERT > Web Part, pick Media and Content under Categories, then Content Editor, and select Add on the right:

Web part picker with Media and Content category and Content Editor next to Script Editor

Script Editor sits next to it. The new part shows an "Edit this Web Part to add content to your page" prompt:

New Content Editor web part on the classic page with the add content prompt

Open its menu (the arrow at the top-right) > Edit Web Part and the prompt becomes Click here to add new content. In the tool pane, Appearance > Chrome Type > None hides the title.

Add HTML and JavaScript with the Source Editor

Select the web part so the ribbon shows FORMAT TEXT, then choose Edit Source in the Markup group:

FORMAT TEXT ribbon tab with Edit Source in the Markup group

Paste the banner snippet into the HTML Source dialog and select OK:

HTML Source dialog with the SPGuides announcement banner code

Save the page. The banner shows, and the script adds "Last checked: 10/26/2026" under the message:

Saved classic page with the blue SPGuides IT announcement banner and Last checked date

For longer code, use a file (next section). Classic client-side calls use JSOM in SharePoint or REST.

Link an HTML file from Site Assets with Content Link

Content Link loads a file of HTML source, so one file can feed several pages. Write the HTML as a fragment, not a full document:

<!-- /sites/SPGuidesClassic/SiteAssets/announcement.html -->
<div id="spgAnnouncement" style="background:#E8F1FB;padding:12px 16px;">
  <h3 style="margin:0;">SPGuides IT announcement</h3>
  <button type="button" onclick="spgShowDetails()">Show details</button>
  <p id="spgDetails" style="display:none;">Ticket portal: /sites/SPGuidesClassic/SitePages/Help.aspx</p>
</div>
<script src="/sites/SPGuidesClassic/SiteAssets/announcement.js"></script>

Put the function in its own .js file, without script tags:

// /sites/SPGuidesClassic/SiteAssets/announcement.js (no <script> tags in a .js file)
function spgShowDetails() {
  document.getElementById("spgDetails").style.display = "block";
}

Upload both to Site Assets (or upload files with PnP PowerShell):

Site Assets library on SPGuidesClassic with announcement.html and announcement.js

Open Edit Web Part, enter /sites/SPGuidesClassic/SiteAssets/announcement.html in Content Link, select Test Link, then OK:

Content Editor tool pane with the Content Link box, browse button and Test Link

Use an https or relative URL, never a file path. After saving, Show details revealed the ticket portal line, so the .js file loaded:

Linked announcement.html rendered with the Show details button and the ticket portal line

The typed banner is gone: a working link wins, and typed content shows only if the link breaks.

Why is the Content Editor web part missing in SharePoint Online?

You’re on a modern page. Microsoft says it isn’t available for modern pages. On the IT Announcements page of /sites/SPGuides, a toolbox search finds nothing; you get modern parts like the Quick Links web part instead:

Modern page toolbox search for content editor returning no web parts

Custom script is blocked. Then Content Editor and Script Editor vanish from Media and Content, even on classic pages. Blocked is the default on modern sites, OneDrive, the root site and admin-created sites.

In the SharePoint admin center, open Active sites > the site > Settings and check Custom scripts:

SharePoint admin center site Settings showing Custom scripts Blocked with Edit

Select Edit, choose Allowed and save. The panel warns that it switches back to Blocked within 24 hours:

Custom scripts panel with Blocked and Allowed options and the 24 hour warning

A SharePoint Administrator can also run either command:

Set-SPOSite "https://contoso.sharepoint.com/sites/SPGuidesClassic" -DenyAddAndCustomizePages 0
# or, with PnP PowerShell
Set-PnPSite -Identity "https://contoso.sharepoint.com/sites/SPGuidesClassic" -NoScriptSite $false

Since Microsoft’s 2024 change, this reset applies to every site (DelayDenyAddAndCustomizePagesEnforcement only postponed it). Existing web parts keep rendering.

Modern alternatives to the Content Editor and Script Editor

Most CEWP jobs have a modern answer without custom script:

Old CEWP jobModern optionRuns script?Notes
Formatted text, tables, linksText web partNoBuilt in for every editor
Embed a video, form or appEmbed web partNoIframe code over HTTPS only; admins control allowed domains
Styled text with headings and listsMarkdown web partNoWrite Markdown, SharePoint renders it
Show sample code to readersCode snippet web partNoDisplays code with a language and theme
Custom HTML, CSS or JavaScriptSPFx web partYes, governedDeployed via the app catalog; admins can turn it off everywhere

Here’s the Markdown web part on the same modern page,:

Markdown web part editor with rendered preview and Dark theme option on a modern page

Embed rejects script tags. For real code, Microsoft recommends SPFx: build a modern script editor web part with SPFx or start with your first SPFx client-side web part.

Common Content Editor problems and fixes

  • A form doesn’t submit: the form element isn’t accepted. Use buttons with JavaScript, or embed a Microsoft Form.
  • Content Link shows nothing: check the URL is relative or https and that readers can open the file.

One caution: anyone with Add and Customize Pages permission can insert script, and nobody can audit who added it.

If you’re moving classic pages to modern ones, these web part guides help next:

Frequently Asked Questions

Is the Content Editor web part available in SharePoint Online?

Only on classic wiki and web part pages while custom script is allowed. Modern pages don’t have it.

How do I get the Script Editor web part in SharePoint Online?

On classic pages it appears under Media and Content once an admin allows custom script (for up to 24 hours). On modern pages, use SPFx.

Can I add JavaScript to a modern SharePoint page?

Only through an SPFx web part from the app catalog. Embed accepts iframe code only.

Is there an HTML editor web part for modern SharePoint pages?

No built-in raw HTML one. Use Text, Markdown, Embed for iframes, or SPFx for custom HTML.

Why does my custom script setting turn itself off?

Microsoft resets the per-site setting to blocked within 24 hours. The steps and affected web parts are in Allow or prevent custom script on Microsoft Learn.

2 thoughts on “Content Editor Web Part in SharePoint Online: Add HTML, Scripts and Modern Alternatives”

  1. Thank you for the post. quick question does SP Online have a built in workflow feature other than Flow something similar to the workflow feature in SP2010 and 2013. However that feature will go away in June 2021.

  2. I hope this tutorial helps you to know about the SharePoint content editor web part. How to use sharepoint content editor web part to add JavaScript or HTML to a SharePoint web part page. Also, we saw how to fix the content editor web part missing in sharepoint online issue.

Leave a Comment