How to Fix SharePoint Online Inserting HTML Entities for Spaces
Question details
The user is experiencing issues where SharePoint Online automatically alters custom HTML code during editing, specifically modifying spaces and paragraph structures.

- Product
- SharePoint Online
- Device & OS
- not provided
- Scenario
- Editing HTML content or source code within SharePoint Online pages and web parts.
- Observed behavior
- SharePoint's content processor replaces standard spaces with the non-breaking-space entity ( ), generates unwanted line breaks in paragraphs, and automatically inserts empty span elements into the code.
Before proceeding, ensure you have a backup of your original, clean HTML code saved locally in a plain text editor. Note that SharePoint's Rich Text Editor has built-in sanitization rules that automatically format and restructure code upon saving.
Report the HTML Modification Behavior to Microsoft Support
Since this involves the underlying behavior of the SharePoint content processor and HTML editor, reporting it with accurate replication steps is the best path toward a long-term resolution.
SharePoint Online utilizes a strict content-processing engine designed to sanitize code and prevent layout breaks. When it encounters raw HTML, it often forces its own formatting rules, which cannot easily be disabled by standard end-users.
Document the specific SharePoint page type, the web part being used, your browser version, and save a sanitized snippet of the affected HTML code.
Reach out to your organization's IT department or SharePoint admin to check if tenant-level custom scripting settings are affecting the editor's behavior.
Sign in to the Microsoft Support forum or have your admin log into the Microsoft 365 Admin Center. Select 'Ask a question' or create a 'New service request' to report the automated code replacement issue.

Use the Embed Web Part as a Workaround
Bypassing the standard Text web part can sometimes prevent SharePoint from aggressively parsing and modifying custom HTML elements and spaces.
Manage Your Document Source Files Offline with WPS Office
Dealing with complex text formatting and auto-correction issues in SharePoint can be frustrating. For your offline document creation and text drafting needs, WPS Office offers a free, lightweight, and highly compatible alternative to Microsoft Office, ensuring your formatting remains intact before you publish content online.
- 1. Download and Install: Get WPS Office from the official website and complete the quick, lightweight installation.
- 2. Draft Your Content: Open WPS Writer to draft your text or code snippets safely without aggressive auto-formatting applied by web browsers.
- 3. Save and Copy: Save your document locally in standard Microsoft formats or copy the clean text to paste directly into your web editor.

Frequently Asked Questions
Why does SharePoint replace regular spaces with the   entity?
SharePoint's Rich Text Editor automatically sanitizes and formats HTML to prevent web layout collapses. Multiple consecutive spaces or specific indentations are often converted into non-breaking space entities (  or ) to ensure the spacing is preserved exactly as typed when viewed on the published web page.
Can I completely disable SharePoint's automatic HTML formatting?
There is no out-of-the-box toggle to completely disable HTML sanitization in standard SharePoint Modern Text web parts. Even if administrators enable custom scripts at the tenant level, standard text web parts will still process and clean up raw HTML upon saving.
How can I insert custom HTML code without SharePoint altering it?
To add custom HTML, CSS, or JavaScript without it being heavily altered by the standard text editor, use the Embed web part or the Markdown web part. For complex elements, developers should consider utilizing the SharePoint Framework (SPFx) for custom web part development.




