Is it possible to add numbering to headings in Confluence?
Asked by Mick Davidson:

Morning,

In Confluence we have headings and we have numbered lists.

Is it possible to combine the two (and then use them as part of a template)?

And to have the numbering working automatically?

The idea is that this would work as it does in Word. So once you start using numbered headings, all subsequent headings get numbered both automatically and down a level each time. For example:

Heading 1 = 1. A Heading

\<some text\>

Heading 2 = 2.1 Help

\<some text\>

Heading 2 = 2.2 I Need

\<some text\>

Heading 2 = 2.3 Your Help

\<some text\>

Etc, etc, so everytime a new heading level was added, the numbering also changed to accommodate that.

Does this make sense?

Cheers.


Answers:
author: Amalia
body: There's a third-party plugin for that: <https://marketplace.atlassian.com/16063>

comments: author: Mick Davidson
body: Amalia, thanks for pointing me in the right direction. :)


author: Dmitry Pashkevich
body: But it's not available for OnDemand instances :(


author: Gert-Jan van de Streek
body: The add-on now has a stable OnDemand counterpart, you can find it [here](https://marketplace.atlassian.com/plugins/nl.avisi.confluence.plugins.numberedheadings-connect "Numbered Headings for OnDemand").


author: Maarten Arts
body: Numbered Headings is now available for Cloud, Server and Data Center:

<https://marketplace.atlassian.com/apps/16063>


author: Jian Yao
body: We've installed Numbered Headings Free on server, but cannot find any button to insert number. Is it possible to add number in free version, or it only provides view function?


author: Maarten Arts
body: [@Jian Yao](/t5/user/viewprofilepage/user-id/1555966)The free version of Numbered Headings uses a macro to number your headings. You can find the macro in the macro browser by search for 'Numbered Headings'.

The button in the editor is only available in Numbered Headings Pro.


author: Arkadiy Birger
body: I can't believe that such a basic and essential wiki/documentation/knowledge space functionality is still not implemented natively in Confluence, and requires either some hacks with consequences or a 3rd party paid plugin. There is a plugin for everything, it seems, and they all add up in costs, both direct and maintenance. We are starting to get feed up with this approach by Atlassian, and looking at moving away from their products completely.

comments: author: Kimi
body: Indeed!


author: Nancy Jaiswal
body: Hi Arkadiy and Kim,

I also agree with your point that must to have features should be provided by Atlassian by default. But you also must appreciate that due to this open platform, many features are available at marketplace in form of add-ons. This way at least user can get away with the problem being faced. Wiki/documentation/ knowledge space has so much varied requirements as per use cases that it is very difficult for a close platform to serve all type of needs single handed.


author: Kimi
body: Hi Nancy Jaiswal,

Indeed that an open platform like Confluence would let developers create more useful add-ons for end users. I do support this mindset and developers should also make money for their living.

But c'mon, we are in 2019 now, not in the '90s anymore.

Numbering to headings should be a must-have feature instead of an addon. If numbering is not a standard default feature, in my point of view, Confluence should not be called a WIKI system.

Not only that, you cannot even increase text size in Confluence neither, to increase text size you have to use the Macro DIV, correct me If I am wrong.

For IT dummies who are working in a Finance or Marketing department, asking them to use Macro DIV for increasing text size, they would curse the system to death :)

If you look at Wordpress, Drupal or other open source CMSs, their WYSIWYG editor includes all these features for free. You might ask me why I will not Wordpress or Drupal instead, well, it's a different topic and debate :)

Cheers

Kim


author: Nancy Jaiswal
body: Hi Kim,

If you will read my comments, I too support basic features in default list of Confluence features. In my opinion it is not the philosophy of letting developers earn their living to prosper a business, it is about providing value to customer.

For providing control on text size, someone from Atlassian can better answer but my take is that any content management system should be controlled one. If you are aware of DITA philosophy, they are trying to provide controlled and limited set of features to content creators so that uniformity and better search ability could be brought to content. My only point of mentioning this is that providing everything that exist in other editors may not always be a good idea in today's world were volume of content being created is tremendous.

Thanks

Nancy


author: Kimi
body: Hi Nancy,

Agreed with most of the thing you wrote here. I don't expect that we must include all features, but if we need to call someone then we don't basically need a smartphone right, we can use a dumb phone to call someone. For me, a wiki system should include numbering to headings heading which is one of the fundamental need to build Wiki pages. Not sure how other thinks, just my opinion :)

Regarding data volume, if we follow Moore's Law then data storage technology might not stop here and will not limit us from saving more data. The questions here is what's in is for me and what Atlassian is willing to give us.

Maybe the Atlassian can give us a new option, they provide us the Confluence system, but we can decide to save our data wherever we wanted, either in Azure, Google Cloud or AWS etc.. :)

Cheers

Kim


author: Arkadiy Birger
body: Hello Nancy,

I am all for "open" platform and the added value added by the 3rd party developers. However, what we are talking about here (and many other cases), is the basic functionality of any CMS/Wiki system that has existed for ages. I should not be required by Atlassian to go and purchase a host of 3rd party plugins (often of questionable quality, and not always available for the full platform offering) to cobble together a decently working Wiki. It's a huge turn off, and will surely drive the user base away from Atlassian altogether.

Right now, the only reason to use Confluence for us, is because of integration with Jira, but we are seriously questioning the value there, that surely can be replicated with a few other ecosystem offerings.

Again, basic formatting is NOT a good candidate for a 3rd party offering, in my opinion. It's like if you ordered a BMW, but had to pay extra for a 3rd party door handles, because it didn't have one in the stock offering.


author: Carl Dunham
body: Are you really surprised? They refuse to support inserting tab characters without a plugin.


author: Katharina Fenner
body: Hi guys,

i've been following your discussion here and wondering if there's still no other way for the numbered headings problem except the plugin or complicated hacks.

I hope every month for a good news in "Whats new in confluence cloud" :)

Do you happen to know something about it?

thanks

Katharina


author: Nancy Jaiswal
body: Hi Katharina,

Unfortunately till now there is no inbuilt direct way of getting headings numbered in my knowledge.

Thanks,

Nancy


author: Katharina Fenner
body: Hi Nany,

that is more than a pity.

thanks for your help.


author: Bartosz Barwikowski
body: I totally agree, it's a shame that such simple feature is not supported by default.


author: Florian Proksch
body: Since all answers here either suggest paid plugins or extensive use of javascript macros I wanted to note that numbering headings can easily be done with a stylesheet (which can be applied globally or space-wide depending on your preferences) using css counters:

```
#content.page.view {
???? /* Set "section" to 0 */
??? counter-reset: section;
}

#content.page.view h1 {
???? /* Set "subsection" to 0 */
??? counter-reset: subsection;
}

#content.page.view h1:before {
??? /* Increment "section" by 1 */
??? counter-increment: section;
??? content: counter(section) " ";
}

/* Continue this scheme as deep as you need */

#content.page.view h2 {
??? counter-reset: subsubsection;
}

#content.page.view h2:before {
??? /* Increment "subsection" by 1 */
??? counter-increment: subsection;
??? content: counter(section) "." counter(subsection) " ";
} 

#content.page.view h3:before {
??? counter-increment: subsubsection;
??? content: counter(section) "." counter(subsection) "." counter(subsubsection) " ";
}
```

comments: author: Andy Ackermann
body: Hi, this doesn't work for me. I want to add section numbering in my PDF report. Where do I have to paste your css?


author: EEAS
body: Very nice, thank you


author: Jian Yao
body: It works fine for viewing document! But during editing, the numbers are not displayed. Any suggestion for display numbers when edit documents?


author: Mike Roels
body: Thanks Florian, works well for me in non-edit mode. Confluence should incorporate a macro to add.remove at will.

Is there a way to apply this per page?


author: Richard Colvin
body: If you place an "html" macro at the top of the page and include the noted css inside a \<style\>\</style\> block inside the macro then it will work for that page only.

Alternatively, the "html" macro can be added to an otherwise empty page and then use the "Include page" macro to include this page. Advantage: any changes made to the style in included page will rendered all pages where it is included.


author: Michel_Levy
body: It works amazing good for me!

Thanks so much for providing this free solution!


author: Filip Pokorny
body: If you'd like the same for editing, copy the same for the .contentLayout2 class. For instance the last chunk would look like following:

```
.contentLayout2, #content.page.view h3:before {
??? counter-increment: subsubsection;
??? content: counter(section) "." counter(subsection) "." counter(subsubsection) " ";
}
```

What's more interesting that this doesn't always work with sections and on some places skips (just some!!). I don't get it, perhaps there really is a CSS magic among us.

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/80560i099BF038B66950AA/image-size/large?v=v2&px=999 "image.png")


author: andreasgounaris
body: Great suggestion.

Following up on [@Richard Colvin](/t5/user/viewprofilepage/user-id/3660357) for applying in selected pages, is it possible to create a no-body custom macro and declare the \<style\>\</style\> in it?

In this way you could skip enabling the HTML macro for security reasons.


author: Florent R_
body: Thanks, it's working perfectly ! But I changed the id and the class to not affect the comments section :

```
#main-content.wiki-content {
/* Set "title1" to 0 */
counter-reset: title1;
}
#main-content.wiki-content h1 {
/* Set "title2" to 0 */
counter-reset: title2;
}
#main-content.wiki-content h2 {
/* Set "title3" to 0 */
counter-reset: title3;
}
#main-content.wiki-content h3 {
/* Set "title4" to 0 */
counter-reset: title4;
}
#main-content.wiki-content h4 {
/* Set "title5" to 0 */
counter-reset: title5;
}
#main-content.wiki-content h5 {
/* Set "title6" to 0 */
counter-reset: title6;
}




#main-content.wiki-content h1:before {
/* Increment "title1" by 1 */
counter-increment: title1;
content: counter(title1) ". ";
}
#main-content.wiki-content h2:before {
/* Increment "title2" by 1 */
counter-increment: title2;
content: counter(title1) "." counter(title2) ". ";
}
#main-content.wiki-content h3:before {
/* Increment "title3" by 1 */
counter-increment: title3;
content: counter(title1) "." counter(title2) "." counter(title3) ". "; 
}
#main-content.wiki-content h4:before {
/* Increment "title4" by 1 */
counter-increment: title4;
content: counter(title1) "." counter(title2) "." counter(title3) "." counter(title4) ". "; 
}
#main-content.wiki-content h5:before {
/* Increment "title5" by 1 */
counter-increment: title5;
content: counter(title1) "." counter(title2) "." counter(title3) "." counter(title4) "." counter(title5) ". "; 
}
#main-content.wiki-content h6:before {
/* Increment "title6" by 1 */
counter-increment: title6;
content: counter(title1) "." counter(title2) "." counter(title3) "." counter(title4) "." counter(title5) "." counter(title6) ". "; 
}
```


author: Precision Plugins
body: [Engineering Essentials](https://marketplace.atlassian.com/plugins/com.precisionplugins.engineeringessentials) has just been released to the public.

This resolves the issue of numbered headings space-wide, without needing to put your content inside a macro.

With Engineering Essentials it is now possible to configure an entire space to have numbered headings. Any enabled space will instantly have it's headings numbered. No additional editing of a page is required. This enforces a consistent look and feel within each space. Additionally, because your content does not need to be wrapped in a macro it does not interfere with page differences, change emails, exports, or other plugins. Ensuring your content will continue to be available into the future, regardless of what plugins you have installed. This simplifies export templates and improves compatibility by defining the correct layout for the particular format within your own templates.

As numbered headings are often required for formal documentation we've also provided the ability to separately force version comments on all changes within a space. Enabling fully automatic change history documentation.

With years of experience supporting Confluence in an engineering environment, Precision Plugins have big plans to plug some small gaps, helping Confluence and other extensions be the best environment for your formal documentation.

Checkout the Engineering Essentials package and let us know what you think here:  
<https://marketplace.atlassian.com/plugins/com.precisionplugins.engineeringessentials>

comments: author: David Meyer
body: This plugin still not supported in Cloud.  
Atlassian has known about this issue for a decade and still makes it another required co$t. I'm not a coder so adding a stylesheet and code as described below isn't really an option.


author: Nick van der Net
body: It is absolutely ridiculous that in 2021 numbered headings and text size differences aren't supported natively. It's not the 20th century anymore. What's next, Atlassian? Smoke signals.  

Poor form....

comments: author: Mike
body: totally agree


author: Shoham Levy
body: Here is my little solution, using JQuery in the HTML MACRO.

```
<script type="text/javascript">

function enumerateHeaders() {
??? var i1 = 0;
??? var i2 = 0;
??? var i3 = 0;

??? AJS.$("#main-content :header").each( function(indx) {
??????? hdr = $(this);
??????? console.log( indx+": "+hdr.text() );
??????? switch (hdr.prop("tagName")) {
??????? case "H1":
??????????? i1++; i2=0 ; i3=0;
??????????? hdr.text( i1+") " + hdr.text() );
??????????? break;
??????? case "H2":
??????????? i2++; i3=0;
??????????? hdr.text( i1+"."+i2+") " + hdr.text() );
??????????? break;
??????? case "H3":
??????????? i3++;
??????????? hdr.text( i1+"."+i2+"."+i3+") " + hdr.text() );
??????????? break;
??????? }
??? });
}

AJS.toInit(function(){
??? enumerateHeaders();
});

</script>
```

comments: author: andreasgounaris
body: Nice!

This approach covers TOC as well, where you can include/exclude sections and subsections via regex provided by the TOC macro.


author: Christian Sprenger
body: As all tickets gets automatically resolved in 3 years, I'll sign myself out from these tickets.

Good-Bye Confluence Server


author: Dmitry Pashkevich
body: Here's the OnDemand version of the plugin (I can't edit Amalia's answer)

<https://marketplace.atlassian.com/plugins/nl.avisi.confluence.plugins.numberedheadings-connect>

Currently it has some issues but I hope they get resolved in near future

comments: author: Gert-Jan van de Streek
body: Since then both the add-on and the OnDemand platform have seen vast improvements. Check our issue tracker for the current status: <http://addons.avisi.com/confluence/numbered-headings/issues.html>


author: Maarten Arts
body: We've recently updated our add-ons website. Anyone looking for help on Numbered Headings can find it here: <http://addons.avisi.com/numbered-headings/help/>


author: Dmitry Pashkevich
body: Related feature request: <https://jira.atlassian.com/browse/CONF-1732>


author: Nancy Jaiswal
body: Hi All,

We have released Auto Numbered Headings plugin [https://marketplace.atlassian.com/apps/1219286](https://marketplace.atlassian.com/apps/1219286?_ga=2.75626389.125996007.1558884604-1120568389.1495123189)[](https://marketplace.atlassian.com/1219286?) which auto numbers the headings of whole space in single click of button. A macro comes along with plugin in case numbering needs to be applied only on selective pages.

comments: author: Christian Sprenger
body: The link does not work (anymore).


author: Maarten Arts
body: [@Chri Bru](/t5/user/viewprofilepage/user-id/1973807)numbering all headings in a whole space is also available on the Server and Data Center version of Numbered Headings. <https://marketplace.atlassian.com/apps/16063>


author: Christian Sprenger
body: Oh, OK, this one I know, but I don't have budget for the plugin.

Anyway, thanks for the new link :)


author: Maarten Arts
body: The app that Nancy posted about 'Auto Numbered Headings' can be found here: <https://marketplace.atlassian.com/apps/1219286>.

I shared the link to an alternative in my previous reply, since it looked like the app wasn't available.


author: Christian Sprenger
body: Cool, thanks for that, I'll look into that :)


author: Aasha
body: [@markusjenu](/t5/user/viewprofilepage/user-id/503403) - Could you please provide step by step to add this code in in confluence

I am trying to replace numbered heading addon in confluence. Could you please help us with this.


author: Eric Hansen
body: I've been using the add-on for a while now, mostly with success, but recently, pages that were created 12-15 months ago now behave very strangely when I try to edit. The page flashes and scrolls elsewhere every time I make a single key-stroke. It is completely unusable. Perhaps this is due to changes Atlassian has rolled out in the cloud but the add-on is no fully compatible with.

I will be reaching out to the add-on supplier for an explanation/fix , but wanted to raise my hand in vote that this functionality should be fundamental / native in Confluence.


author: Markus
body: I created a script (copied some code from <https://stackoverflow.com/questions/5127017/automatic-numbering-of-headings-h1-h6-using-jquery> ) you can use in Confluence editor. You can add the script to usermacro and add the macro to header via space tools -\> look and feel.

Hotkey hh and a button in the editor.

```
<script>

 AJS.whenIType('hh').execute(function () { //hotkey
 addIndex();
 });

function addIndex() {
 var indices = [];
 jQuery("#wysiwygTextarea_ifr").contents().find("h1,h2,h3").each(function(i,e) { //.find("h1,h2,h3,h4,h5,h6") if you want all headings numbered
 var hIndex = parseInt(this.nodeName.substring(1)) - 1;
 if (indices.length - 1 > hIndex) {
 indices= indices.slice(0, hIndex + 1 );
 }
 if (indices[hIndex] == undefined) {
 indices[hIndex] = 0;
 }
 indices[hIndex]++;
 if(jQuery(this).text().indexOf(indices.join(".")+" ") <0 ){
 jQuery(this).prepend(indices.join(".")+" ");
 }
 });
}

AJS.toInit(function(){
 AJS.$('#rte-toolbar > div.aui-toolbar2-primary.toolbar-primary').append('<ul class="aui-buttons"><li class="aui-button" id="addIndex">Number headings</li></ul>')
 AJS.$("#addIndex").click(function(e) {
 e.preventDefault();
 addIndex();
 });
});

</script>
```

comments: author: lubos tapusik
body: Hello Markus, just wanted to thank you. Works great!


author: Markus
body: Few more tweaks:

1. Removes old heading numbers
   1. Removes all numbers from the start of the heading (including dates for example)
2. does not lose inline comments or inline macros

```
function addIndex() {
 var indices = [];
 jQuery("#wysiwygTextarea_ifr").contents().find("h1,h2,h3").each(function(i,e) { //.find("h1,h2,h3,h4,h5,h6") if you want all headings numbered
 var hIndex = parseInt(this.nodeName.substring(1)) - 1;
 if (indices.length - 1 > hIndex) {
 indices= indices.slice(0, hIndex + 1 );
 }
 if (indices[hIndex] == undefined) {
 indices[hIndex] = 0;
 }
 indices[hIndex]++;
 var lapset=[];
 jQuery(this).children().each(function(){
 var text = AJS.$(this).prop('outerHTML');
 lapset.push(text);
 });
 jQuery(this).html(indices.join(".")+". " + removeNo(jQuery(this).text()));
 jQuery(this).append(lapset.join(""));

 });
}

function removeIndex(){
 jQuery("#wysiwygTextarea_ifr").contents().find("h1,h2,h3,h4,h5,h6").each(function(i,e) {
 var lapset=[];
 jQuery(this).children().each(function(){
 var text = AJS.$(this).prop('outerHTML');
 lapset.push(text);
 });
 jQuery(this).text(removeNo(jQuery(this).text()));
 jQuery(this).append(lapset.join(""));
 });
}

function removeNo(str) {
 let newstr = str.trim();
 newstr = newstr.replace(/[\u00A0\u1680?\u180e\u2000-\u2009\u200a?\u200b?\u202f\u205f?\u3000]/g,' ');
 if(IsNumeric(newstr.substring(0,newstr.indexOf(' ')))){
 return newstr.substring(newstr.indexOf(' ')+1).trim();
 }
 return newstr;
}

function IsNumeric(num) {
 num = num.split('.').join("");
 return (num >=0 || num < 0);
}
```


author: lubos tapusik
body: I noticed it also added some dots to the numbering that weren't there before.

Thanks a lot again.

Btw I call the function removeIndex() right before addIndex(). I hope that's the intended usage.


author: Markus
body: I have a dedicated button for the removeIndex() function that I can use if I want to remove the numbers from headings. You don't have to call the function before addIndex, the addIndex removes the numbers too.

```
jQuery(this).html(indices.join(".")+". " + removeNo(jQuery(this).text()));
```

```
AJS.$('#rte-toolbar > div.aui-toolbar2-primary.toolbar-primary').append('<ul class="aui-buttons"><li class="aui-button aui-button-compact" id="addIndex">Number headings</li><li class="aui-button aui-button-compact" id="removeIndex">remove index</li></ul>')
 AJS.$("#addIndex").click(function(e) {
 e.preventDefault();
 addIndex();
 });
 AJS.$("#removeIndex").click(function(e) {
 e.preventDefault();
 removeIndex();
 });
```


author: lubos tapusik
body: Alright, I see it now. Thank you.


author: Elahd Bar-Shai
body: Thanks for posting this. I've converted your code into a TamperMonkey script so that those of us without admin access to Confluence can use it.

1. <https://greasyfork.org/en/scripts/381252-confluence-auto-numbered-headings>
2. <https://gist.github.com/elahd/28f64feddd9ece56f4f0566d195d0cbd>


author: Jean-Marc Pascal
body: Hello [@markusjenu](/t5/user/viewprofilepage/user-id/503403) ,

I am new in installing this. Installation successful but seems not working on current Confluence Cloud version: I don't see the icon in the menu bar:

![Confluence editor menu bar.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/147101iABDC88AE202D9620/image-size/large?v=v2&px=999 "Confluence editor menu bar.PNG")

Best Regards.


author: Vijay Patil
body: Hi All,

It seems like a very very long pending issue with Confluence.

I found something that sort of works

<http://philarcher.org/diary/2011/numbering/>

The script works really really well, except the headings start at 3 and everything (even things in the sidebar) get numbered. It will be awesome if someone can figure out how to get this working. I know that there are free plugins, but they clutter up the document and remove the clarity. If we get this working, we can simply put this into \<head\> and then bingo, everything is right the way it should be.

```
window.onload = function () {  var elements=document.getElementsByTagName('*');  var numbers=[0,0,0,0,0,0,0];  for (var i in elements) {     var e=elements[i];    if(!e||!e.tagName||!e.tagName.match(/^H([1-6])$/)){continue}    var eLevel=RegExp.$1;    var txt='';    numbers[eLevel]++;    for(var l=1;l&lt;=6;l++) {      if(l&lt;=eLevel){        txt+=numbers[l]+'.'      } else {        numbers[l]=0;      }    }    e.textContent=txt+' '+e.textContent.replace(/^[0-9\.\s]+/,'');  }}
```

To try this,

Put the current script in the HTML macro at the end of the page.

I think we need to change this line

```
var elements=document.getElementsByTagName('*');
```

The document should be replaced by something that confluence knows as 'page contents'. Please see if you guys can solve this!


Tags: numbered-heading