Possible Duplicate:
Why are there no line numbers in the code listings?

Hi, Should not there be line numbers with the code samples in questions and answers? it makes it easier to refer in the description.

  • 1
    I second this request. Line numbers if implemented properly should not make copying code difficult as the other comments seem to suggest. I am sure you have seen plenty of other sites with copy-safe line numbers. google search for "code show line numbers blog" gives akomaenablog.blogspot.com/2009/05/… which is pretty copy-safe
    – abel
    Commented Oct 2, 2010 at 10:31

4 Answers 4


I'm not so sure... I always find line numbers a distraction; I don't show them when I'm coding, so why would I want them now?

If I want to highlight a code in one of my samples, I add a comment...

var z = x / y; // <==== throws error

If it is the OP's line, I just quote it..., for example: the line "var z = x / y" might throw if y is zero; is this possible with your data?

If this did happen, I wouldn't want to see it on single-line answers - there would be a lot of 1s...


Line numbers might make it easier to refer to a specific line. On the other hand, they'd make it much harder to copy stuff off the site and paste it in your editor.

  • Very good point. I do this a lot.
    – nb69307
    Commented Aug 30, 2009 at 9:03

As well as all the other points (in particular the "copy/paste" argument), I'd add the following.

Line numbers are useful in longer pieces, where you refer to "line 4: set up the connection, line 5: provide credentials, line 8: set up the query" and so on. However, I've found that the vast majority of StackOverflow questions (certainly ones I'm involved in) don't have such quantities of code in the answer (explanation isn't always needed or given in any longer question's code segments), so any explanation needed is usually given in the text or in comments.

When I'm publishing code segments on sites, and need to provide notes for specific lines, I usually use something like this:

line_of_code();  // 1
final_code();    // 2

This has the benefits that:

  • it's not clogging up the screen for those who don't like seeing line numbers
  • it doesn't bother copy/pasters
  • it's got the annotating benefits; I can say "At line marked 1 above, ..."

The most obvious benefit: we've already got the ability to do this now :)


Adding line numbers could help make the answer more understandable, sometimes I wish I could reference a specific line in the code and it's a bit hard without actual line numbers.

I would suggest adding a "copy this" link on top of the code that way we can copy the code without the line numbers.

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