I’ve long been on the “spaces” side of the tabs vs. spaces preference debate. I think there is just something that feels sturdy and reliable about spaces. I’m wrong though. Despite not having swapped over most of my projects, I think that, objectively, tabs are the better choice.

  1. It doesn’t actually matter in code editors. There is no visual difference or UX difference. Either way, press the tab key, code indents using your preference. On any major project, that preference is probably set with an EditorConfig file. And/or, Prettier is used and configured to make sure indentation is consistent. As developers, we care more about consistency than individual preference.
  2. If tabs are used, tabs can be configured on an individual basis to be of a certain length. So if you prefer that short 2-space length, you can have that, while someone else on the project can prefer an airy 6-space length, but you’re both using tabs.
  3. Tabs solve two accessibility issues: #2 above is one of them, and the other is braille displays.

So since it doesn’t impact experience, allows for individual preference matching, and is more accessible, that makes tabs objectively better.

There is also the matter of reading code on the web itself. I was just reading Dynamic Tab-Size Demo Using CSS Custom Properties In JavaScript from Ben Nadel and it makes the same point as #2 above. There is a tab-size property in CSS, and that allows for control over how visually indented code can be in a way spaces can’t. See:

CodePen Embed Fallback