Maximum Line Length

Many code standards recommend a maximum number of characters per line. This article explains why such a limit is desirable and looks into what the limit should be.

Why limit line length?

The primary aim of keeping lines short is to avoid horizontal scrolling, which makes code tedious to read.

Short lines are especially helpful when little space is available in the editor. For example, this might be the case when viewing two files side-by-side, or when using a text editor in the command line.

Side-by-side editing in Sublime

What should the limit be?

The table below shows the character limits recommended by various coding standards. Most recommend a limit between 80 and 100 characters.

LanguageCoding StandardMaximum Length
JavaScriptDouglas Crockford80
CSSHarry Roberts80
GoEffective GoNo limit

Note how Effective Go doesn't recommend a fixed maximum:

Go has no line length limit. Don't worry about overflowing a punched card. If a line feels too long, wrap it and indent with an extra tab.

Other code standards in the list also recommend that the limit should be ignored when that makes the code more readable. A common example is a long URL that's pasted into the source code.

Aim for a maximum length of around 80 to 100 characters per line, but you don't have to follow it religiously. Talk to other members of your team to see if they have any specific preferences based on their workflow and the tools they're using.