SharePoint Document Issues

Fix CSS Disappearing After Saving a SharePoint Online Page

Muhammad TalhaMuhammad Talha Nov 22, 2026 868 views

Question details

The user needs custom CSS to remain on a SharePoint Online page after saving.

Fix CSS Disappearing After Saving a SharePoint Online Page
Product
SharePoint Online
Device & OS
not provided
Scenario
Adding custom CSS to a SharePoint Online page while editing it.
Observed behavior
The CSS works in preview but disappears after the page is saved.
Before you start

Check whether the page uses the classic or modern SharePoint experience. The Content Editor Web Part is intended for classic pages and may be unavailable if custom scripting is restricted.

Solution 1Recommended

Add CSS through a Content Editor Web Part on a classic page

Use this approach on a classic page where the Content Editor Web Part and custom scripting are available.

SharePoint can remove unsupported HTML or style elements entered directly into a page. A Content Editor Web Part provides a separate place for classic-page content, although site restrictions can still prevent custom code from being saved or run.

1
Edit the classic page

Open the page in SharePoint Online and select Edit Page from the settings menu or page ribbon.

2
Add the web part

Choose Insert > Web Part, select Content Editor under Media and Content, and add it to the page.

3
Enter the CSS

Edit the Content Editor Web Part, open its HTML source editor, and add your CSS inside a style element. For example, use a complete declaration such as border: 5px dotted #ddd.

4
Use a stable selector

Use your browser's Inspect tool to identify an appropriate class instead of relying on a web part ID that may change. For reusable styling, consider linking a stylesheet where your site's policies allow it.

5
Save and verify

Save the web part and the page, then reload the page to check whether the styling remains.

Add CSS through a Content Editor Web Part on a classic page
If the web part is unavailable: Ask your SharePoint administrator about site policies and custom scripting restrictions. Do not assume that using a web part bypasses those restrictions.
Free Microsoft Office alternative

Create documents for your SharePoint workflow with WPS Office

WPS Office is a free, lightweight alternative for creating and editing Office documents. Its familiar interface and Microsoft Office format compatibility make it easy to move existing files into your workflow. It does not fix SharePoint page CSS.

Create and edit documents that can be stored in SharePoint librariesCompatible with Microsoft Office formats such as DOCX, XLSX, and PPTXFamiliar editing interface for an easier transitionFree and lightweight office tools
microsoft office alternative - wps office

Frequently Asked Questions

Why does my CSS work in preview but disappear after I save?

SharePoint page-editing restrictions can remove unsupported HTML or style elements during saving. On a classic page, try adding the CSS through a Content Editor Web Part if your site permits it.

Can I add a Content Editor Web Part to a modern SharePoint page?

No. The Content Editor Web Part is a classic-page feature. For a modern page, discuss an appropriate SharePoint Framework web part or extension with your developer or administrator.

Why is my CSS border not showing even when the rule is present?

Check the declaration in your browser's Inspect tool. Specify the width, style, and color together, such as border: 5px dotted #ddd.

Should I use a web part ID as my CSS selector?

Avoid it when possible because the ID can change as web parts are added or removed. Use your browser's Inspect tool to find an appropriate stable class, or scope styles to a component you control.

What if I cannot find the Content Editor Web Part?

Confirm that you are editing a classic page and check Insert > Web Part > Media and Content. If it is missing, ask your SharePoint administrator whether site settings or custom scripting restrictions prevent its use.