I've got the following code in the HTML editor.
<div><img src="image.jpg"></div>

When I click publish a non-breaking space is added to the markup.
<div><img src="image.jpg">&nbsp;</div>

How can I stop SharePoint from inserting these tags?! Help!

3 Answers 3



<div><img src="image.jpg" /></div>
  • I should have specified my markup, the IMG tag does have a closing "/" May 24, 2016 at 14:47
  • Unfortunately, that didn't change anything. May 24, 2016 at 14:47
  • Try this <img src='image.jpg'></img> May 24, 2016 at 14:49
  • That gets changed to a single <img /> tag. May 24, 2016 at 14:51
  • Try adding an alt to the tag May 24, 2016 at 14:52

A similar issue occurs when you use an h1 tag. SPD will add a &nbsp; after the opening tag. A workaround is to surround the text with a span tag. Try this for your issue--

<div><span><img src="image.jpg"></span></div>

With self closed image tag (XML prefers a closing tag.):

<div><span><img src="image.jpg"/></span></div>

SPD = POS editor.

  • This does not work either. It just adds the &nbsp; after the </span>. Nov 8, 2018 at 21:13
  • Can you try in a content editor web part? I just tried and the editor replaces <div><img src="image.jpg" /></div> to <div><img src="image.jpg" alt=""/></div>. So basically it just adds the alt tag.
    – Ahmad Zia
    Nov 9, 2018 at 0:30

I have found that this works most of the time.

If you add the non-breaking space entity (&#160;) before Sharepoint does, then you have a little more control over where it ends up.

If you save this HTML in the Sharepoint editor:

  <img src="myimage.jpg" alt="" />

it will get saved as:

  <img src="myimage.jpg" alt="" />&#160;

The only real way to make the space go away is to hide it by reducing the font size to 0 or programmatically remove them with script (ugly).

To hide the space, update the HTML in the editor to include the &#160; before Sharepoint does and it will leave it alone. Wrap your <img> tag in a span and set that to have no font size.

Updated HTML for the editor:

  <span class="text-zero"><img src="myimage.jpg" alt="" />&#160;</span>

The CSS for the class text-zero would be:

.text-zero {
  font-size: 0;
  line-height: 0;
  display: block;

If you don't add the &#160 in your HTML in the editor, it may end up adding it after the closing </span> tag.

I can't guarantee that this will work 100% of the time, because Sharepoint puts the non-breaking space characters after some images and not others, but it has worked in a lot of instances and seems more stable than some other solutions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.