SE sites use Google Code Prettify for code formatting. While it's still up in the air as to whether we would be able to get SE to use community-voted code formatting, I've been experimenting with Prettify.

There are a few options for line numbering in Prettify, and I was interested to know what everyone thought would be best to use, if we were to have our own formatting.

I will post 3 answers with the different options. Please up- or down-vote according to your preference.

PS: Please don't mind the colors right now, haven't got that far yet.

PPS: I took the code from here in case you are curious.


3 Answers 3


All lines numbers

To clarify, as the question surfaced a few times, line numbers do not affect copy & paste, in other words, line numbers are not stored in the clipboard when you select the code.


After some experimentation, it appears the line numbers do carry over using IE 11, but not on other browsers tested. This would make the copied code not compile until they are removed. This may be a pretty big deal breaker, as SE supports IE 11. (thanks @MarcAndre for pointing out)

Also, it would be nice if answers could retain correct line numbers when posting snippets; however there is no way to make a code block not start with line 1. Code in the question occasionally changes (i.e. it might get formatted a bit better) - answers referencing specific line numbers would potentially become confusing.

enter image description here

  • 9
    \$\begingroup\$ Having line numbers is a plus (IMO) since it makes it easier to refer to the code you have in mind. Especially in code review we deal with big chunks of code as it's good to submit a working code. \$\endgroup\$
    – Mehrad
    Jan 15, 2015 at 0:17
  • 1
    \$\begingroup\$ How does having line numbers impact the copy/paste process? \$\endgroup\$
    – rolfl
    Jan 15, 2015 at 1:40
  • \$\begingroup\$ It has no impact on my machine, as in, line numbers are left out of the clipboard. I'm on Mac though, you're welcome to try it from your end: github.com/Cardshifter/cardshifter.github.io/blob/develop/… \$\endgroup\$
    – Phrancis
    Jan 15, 2015 at 1:43
  • \$\begingroup\$ @rolfl I got independent confirmation it works fine, see this \$\endgroup\$
    – Phrancis
    Jan 15, 2015 at 3:27
  • 1
    \$\begingroup\$ The IE 11 is a pretty big deal breaker IMHO , since SE support that browser. I don't think using the edit option would be view as a valid alternative. \$\endgroup\$
    – Marc-Andre
    Jan 16, 2015 at 19:15
  • 1
    \$\begingroup\$ Can we change the starting number? While we prefer complete code, it's not actually a requirement. Also, it would be nice if answers could retain correct line numbers when posting snippets. \$\endgroup\$
    – Brythan
    Jan 16, 2015 at 22:00
  • \$\begingroup\$ Unfortunately not, it always starts at 1 for each code block. The other thing about snippets, that I'm not sure. \$\endgroup\$
    – Phrancis
    Jan 16, 2015 at 22:29
  • 3
    \$\begingroup\$ Hm, I don't know - code in the question occasionally changes (i.e. it might get formatted a bit better) - answers referencing specific line numbers would potentially become confusing. I think quoting a snippet is more robust. \$\endgroup\$
    – ChrisWue
    Jan 19, 2015 at 19:31
  • 2
    \$\begingroup\$ The more I think about it, and as much as I think line numbers would be/look nice... There are a few obvious drawbacks that may be more trouble than it's worth... Perhaps we should leave well enough alone? \$\endgroup\$
    – Phrancis
    Jan 19, 2015 at 19:45
  • 5
    \$\begingroup\$ @ChrisWue that's an invalid edit :( reformatting code violates the guidelines... but yes I also think quoting a snippet is more robust. It's also more obvious and doesn't require checking back against the answer \$\endgroup\$
    – Vogel612
    Jan 19, 2015 at 19:46
  • 1
    \$\begingroup\$ Not a fan of the dark colors. It's really hard on the eyes. \$\endgroup\$
    – cimmanon
    Jan 19, 2015 at 20:13
  • \$\begingroup\$ Yeah I'll make a separate post once I start tinkering with colors and such. \$\endgroup\$
    – Phrancis
    Jan 19, 2015 at 20:23
  • \$\begingroup\$ It should be possible to make the line numbers not copy on IE11. Separate the line numbers from the code (tables?) or replace the line numbers with a .png. This one implementation not working on IE should not ruin the improvement. \$\endgroup\$
    – nwp
    Jan 21, 2015 at 10:54
  • \$\begingroup\$ @nwp You're welcome to fork it from my repo if you have any idea how to make it work. This is where I keep the working code. \$\endgroup\$
    – Phrancis
    Jan 21, 2015 at 15:54
  • \$\begingroup\$ I think line numbers are a bad idea. (i) They will tempt people to refer to code by line number instead of quoting the relevant portion, but that will be disastrous for readability of answers, because you'll have to keep referring back and forth. (ii) They waste horizontal space which is very limited on mobile devices. (iii) They don't even help when there's more than one code block. \$\endgroup\$ May 13, 2015 at 9:13

No line numbers

This is the setting that is currently in use on CR.

enter image description here


Numbers every 5 lines

Note that the different colored lines are also optional, that can be changed easily.

enter image description here

  • 14
    \$\begingroup\$ This one feels a tad silly. If you're going to dedicate the space to line numbers anyway, might as well number them all! If the justification is "less clutter," I find that having odd line numbers draws my attention to them more than just numbering everything because it's unexpected. \$\endgroup\$ Jan 15, 2015 at 9:13
  • 8
    \$\begingroup\$ I certainly don't disagree! \$\endgroup\$
    – Phrancis
    Jan 15, 2015 at 14:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .