Sign up ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

Is there a way to automatically number headings in Google Docs?

It used to be possible with CSS but this feature isn't supported anymore in the new Google Docs version.

share|improve this question

migrated from Feb 14 '12 at 10:14

This question came from our site for computer enthusiasts and power users.

7 Answers 7

up vote 4 down vote accepted

Well, it seems easier to do that by scripting the document like this:

var pars = DocumentApp.getActiveDocument().getBody().getParagraphs();
var counterh1 = 0;
for(var i=0; i < pars.length; i++) {
    var par = pars[i];
    var hdg = par.getHeading();
    if (hdg == DocumentApp.ParagraphHeading.HEADING1) {
          var content = par.getText();
          var chunks = content.split('\t');
          if(chunks.length > 1) { 
          } else {
share|improve this answer
You're right, google scripting is so powerful! – Martin Delille Jul 22 '13 at 16:53

I did a quick comparison between Table of Contents app and the Numbered Headings apps using Firefox. Admittedly, this info will become dated if things improve for both apps:

  1. There is no online help for use of the Table of Contents app (either never was or it got taken down) The help button points to a page that tries to up-sell you with a trial instead of providing help. Heading Numbers provides a FAQ at
  2. The Table of Contents and Heading Numbers apps don’t play well together in terms of renumbering the headings: I created numbered headings using Heading Numbers, and applied similar headings using Table of Contents, and it added two sets of numbers into the headings. The same is the case if you reverse the order by applying the headings using Table of Contents first, then Heading Numbers.
  3. Table of Contents doesn’t have the same number of heading styles as Heading Numbers does.
  4. But having the side-bar in Table of Contents is still handy. I select As Is from the Table of Contents side bar and am able to click the refresh button to see and navigate the table of contents.
  5. Heading Numbers has a Clear operation. Table of Contents does not. The Clear operation does not fix the interaction issue described above, which is quite painful because you have to manually fix them.
  6. Neither app updates a Table of Contents that is inserted into the document (via the Insert/Table of Contents menu).
share|improve this answer

Now there is an add-on called Heading Numbers that you can use to add any custom numbering style. It allows you to choose/define, update and remove automatic heading numbers.

Predefined styles:

  • 1.2.3 – Digits without trailing dot
  • 1.2.3. – Digits with trailing dot
  • a.b.c – Lowercase letters
  • A.B.C – Uppercase letters
  • i.ii.ii – Lowercase roman
  • I.II.III – Uppercase roman
  • 1) a) i) – Changing style followed by a trailing parenthesis

I released this add-on a couple of weeks ago. Check it out on my homepage or in the add-on store.

share|improve this answer
The FAQ entry for How do I add automatic heading numbering? says: "If the add-on is installed, choose “Add-ons” -> “Heading numbers“, and then choose your style." But when adding it to a document, that did not show up. I had to reload the document before "Heading numbers" showed up in the menu. Probably a Google bug and not a bug in the Heading numbers app. – bgoodr Sep 20 at 15:41

Hope this helps


Instructions to use:

In a Google Doc

Go to Tools > Script Editor 
Select the option to create the script for Google Docs.
Replace the Content of with the code below.
Save it and name the project as say addHeaderNumbering.
Click play icon for the function addHeaderNumbering (authorize it when asked).


function addHeaderNumbering () {
  var pars = DocumentApp.getActiveDocument().getBody().getParagraphs();
  var counterHeader = [0, 0, 0, 0, 0, 0];

  for(var i=0; i<pars.length; i++) {
    var par = pars[i];
    var hdg = par.getHeading();
    if (hdg == DocumentApp.ParagraphHeading.HEADING1) {

      _addNumberingForHeaderType(DocumentApp.ParagraphHeading.HEADING1, par, 0, counterHeader);
    } else if (hdg == DocumentApp.ParagraphHeading.HEADING2) {
      _addNumberingForHeaderType(DocumentApp.ParagraphHeading.HEADING2, par, 1, counterHeader);
    } else if (hdg == DocumentApp.ParagraphHeading.HEADING3) {
      _addNumberingForHeaderType(DocumentApp.ParagraphHeading.HEADING3, par, 2, counterHeader);
    } else if (hdg == DocumentApp.ParagraphHeading.HEADING4) {
      _addNumberingForHeaderType(DocumentApp.ParagraphHeading.HEADING4, par, 3, counterHeader);
    } else if (hdg == DocumentApp.ParagraphHeading.HEADING5) {
      _addNumberingForHeaderType(DocumentApp.ParagraphHeading.HEADING5, par, 4, counterHeader);
    } else if (hdg == DocumentApp.ParagraphHeading.HEADING6) {
      _addNumberingForHeaderType(DocumentApp.ParagraphHeading.HEADING6, par, 5, counterHeader);

function _addNumberingForHeaderType(headerType, paragraph, initIndex, counterHeader) {
  counterHeader[initIndex] = counterHeader[initIndex] + 1;
  var currCounter = _getCurrenNumbering(initIndex, counterHeader);
  for(var ii = initIndex + 1; ii < counterHeader.length; ii++) {
    counterHeader[ii] = 0;
  var content = paragraph.getText();
  var chunks = content.split('. ')

  var result = 'ok'
  if(chunks.length > 1) {

    paragraph.setText(currCounter+'. '+chunks[1]); 
  } else { 
    paragraph.setText(currCounter+'. '+chunks[0]);

function _getCurrenNumbering(initIndex, counterHeader) {
  var value = '';
  for ( var i = 0; i <= initIndex; i++) {
    if (value) {
      value += '.';
    value += counterHeader[i];

  return value;
share|improve this answer

I know that this might not be relevant for the OP anymore, but there is now a posibility to use add-ons. There is a function in the Table of Contents add-on, where you can select the numbering scheme for the heading and it does the required:


I hope that it will be useful to something.

Link to the add-on

Disclaimer: This might be working only on Chrome, but hey, at least it works.

How to use: There is a widget on the right hand side and at the top of it you can select your numbering scheme and refresh the headings with the usual refresh button.

So just set the numbering scheme and update the heading after you are done with editing and you will have correct and updated section/subsection/... numbers.

share|improve this answer
Excellent. To me this is "the" answer. Works on Firefox for me. – AronVanAmmers Sep 22 '14 at 11:38

What I was looking for was getting the headings like so:


and I could not find any, so I did my own script, I posted it here!topic/docs/w4MXeqJaefU

share|improve this answer

Actually it is possible even without editing the HTML/CSS. I'll give you an example with a blank document but once you'll figure out how it works you will be able to do it on already existed document. Also if you are not already using the keyboard shortcuts I would suggest you to start using them (in this example I'm using Mac's shortcuts, but you can easily find the correct ones for your own OS).

  1. Create a new document
  2. Apply Heading 1 (⌘⌥1)
  3. Apply Numbered List (⌘⇧7)
  4. Type "First" and press Return
  5. Apply Heading 1 (⌘⌥1), type "Second" and press Return
  6. Apply Heading 1 (⌘⌥1), type "Third" and press Return

At that Point you should have something that looks like this:

Numbered Headers in Google Docs

  1. Get your cursor at the end of the First header
  2. Press Return twice
  3. Type "Hello World!"
  4. Repeat the procedure for the rest of the headers

Now your document should look something like this:

Numbered headers with some extra text in between

As you might noticed the automatic numbering is still there and you can easily experiment by adding more Headers as you wish and even numbered sub-headers if needed. I'm not going into more details, but here you can check an example with nested numbered lists with correct formatting for Headers:

Complete example for numbered headers

share|improve this answer
This looks nice but doesn't seem to be fully functional: how do I add a new heading 1 at the end of the document? If I set the heading 1 and then apply the number list it start numbering from 1... – Martin Delille Feb 29 '12 at 16:54
@tinmaru That's a little bit tricky.. but still doable. Go to the end of the previous header that you want to continue the numbering, press enter and then apply heading. Afterwards cut that (never mind for the number that is left behind), go to the end of the document and paste it. You'll see that the number is correct now, so simply go and fix the previous error by deleting the empty header if any. – Lipis Feb 29 '12 at 19:04
Nice! That's a trick ;) – Martin Delille Mar 1 '12 at 19:00
@tinmaru if the answer is helpful don't forget to mark it ;) – Lipis Mar 2 '12 at 13:57
yes i'm sorry I totally forgot! Thanks for your help :) – Martin Delille Mar 4 '12 at 18:05

protected by Community Mar 23 at 19:51

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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