Fix CSS Disappearing After Saving a SharePoint Online Page
Question details
The user needs custom CSS to remain on a SharePoint Online page after saving.

- 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.
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.
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.
Open the page in SharePoint Online and select Edit Page from the settings menu or page ribbon.
Choose Insert > Web Part, select Content Editor under Media and Content, and add it to the page.
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.
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.
Save the web part and the page, then reload the page to check whether the styling remains.

Use a SharePoint Framework extension for a modern page
Use a SharePoint Framework (SPFx) solution when a modern page needs custom functionality or styling.
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.

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.




