Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

[CONFLUENCE] How can I remove empty whitespace / paragraph tags?

One common problem with Confluence is that it frequently generates phanatom white space above and below elements such as macros, tables, images, etc. Removing them can be an impossible task. How can you do it?

3 answers

1 accepted

1 vote
Answer accepted

The answer to this is to use jQuery. Place the following JavaScript in the "At end of the BODY" section of your Custom HTML (this is not possible AFAIK with Confluence OnDemand).

<script type="text/javascript">
jQuery('p').each(function() {
    var $this = $(this);
    if($this.html().replace(/\s| /g, '').length == 0)

Full credit for this script goes to "ruslyrossi" on StackOverflow (

Where exactly do I need to put this code? I am already using a set of code for PDF export. so, Please suggest.


Hi Anindita,

This solution leverages the "At end of the body" feature that places custom HTML/Javascript code at the end of every Confluence page.

  • Go to Confluence Administration
  • Select Custom HTML on the left panel, under the Look and Feel section
  • On the "At end of the body" box, insert the code

For Confluence Cloud I found that if you position your cursor immediately to the left of a macro while editing, a single vertical line will appear. If you hit the backspace (delete) key then that space will go away briefly and then reappear. If you do that for all macros on the page then the <p><br></p> will no longer be inline between the macros after saving/publishing.

Thank you so much, man!

You can't imagine how long I was fighting with that extra space until I noticed your comment.

This is such a tedious process... I wish Atlassian did not introduce them in the first place.

I had hoped that it would no longer be an issue with the new editing experience but seems to still be there. I do most of my docs in Google Docs now anyway but still need to use Confluence for the JSD KB Articles. Maybe it gets fixed on the next UX release.

Agreed - it is tedious and should be unnecessary. 

AJS.toInit(function() {
   AJS.$("document").ready(function() {

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Confluence

What do you think is the most *delightful* Confluence feature? Comment for a prize!

- Create your own custom emoji 🔥 - "Shake for Feedback" on mobile 📱 - An endless supply of GIFs via GIPHY 🤩 Is there anything quite as nice as a pleasant surprise? Comment below with what...

335 views 23 8
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you