DEV Community

Cover image for Why we should default to Tabs instead of Spaces for an 'accessible first' environment
Alexander Sandberg
Alexander Sandberg

Posted on • Updated on • Originally published at alexandersandberg.com

Why we should default to Tabs instead of Spaces for an 'accessible first' environment

I'm sure you've come across the age-old, opinion-based debate of 'Tabs vs. Spaces' for indentation before. It has been going since forever, and there seem to be valid reasons for both sides:

Tabs...

  • smaller files because it's just 1 character
  • that's what they're used for
  • you can customize your own indentation width (👈 keep this one in mind)

Spaces...

  • to avoid problems in whitespace-sensitive environments
  • because you know what you'll get, and consistency is key

But, there's more to this than just personal preferences. u/ChaseMoskal recently posted a very insightful and eye-opening post on Reddit with the title "Nobody talks about the real reason to use Tabs over Spaces".

The one real reason to use tabs over spaces

In his post, Chase explains his own experience of using spaces at his workplace, and the negative effects it had on co-workers with visual impairment.

One of his co-workers uses a tab-width of 1, to avoid huge indentations when using a large font-size.

Another co-worked of his is using a tab-width of 8 because that works best for his situation with a wide monitor.

I see people saying "tabs lets us customize our tab-width", as though we do this "for fun" — Chase

By using tabs in our projects, we allow these kinds of customizations that are essential for people with visual impairment. Custom tab-widths might seem like an unnecessary thing to most, but some people rely on it—and we can not ignore that.

Accessible first

We simply can't "convert" everyone to one side or the other, there's no question about it. Everyone has their own preferences, and we should celebrate that freedom—that we have the ability to make our own choices.

But with that said, we should also make sure to include everyone, and that means respecting and using accessible tools like the Tab-character.

Much like designing for 'mobile first'—making sure everyone, no matter what device, has a great experience with your product—we should create an 'accessible first' environment, by making sure that everyone has the same ability to work, whether it's at the workplace or on an open-source project.

I thought Chase put it perfectly when he said in his post that "...there's just no counter-argument that even comes close to outweighing the accessibility needs of valued coworkers".

Conclusion — Accessible first, personal preference second

By defaulting to tabs, we make sure that everyone has a great experience working together with others, no matter their own abilities.

And if you prefer spaces, feel free to use an auto-formatting tool that converts tabs to spaces when opening a file (all modern editors have these). Just make sure that the spaces get converted back to tabs before anyone else has to work on your code.

Only by making sure everyone has the same capability can we maximize our combined potential ❤️

I have myself decided to switch to tabs indefinitely after learning about this, but I'd love to hear your thoughts on this as well. Feel free to start a discussion below!

Thank you so much for reading. I hope you all have an amazing weekend. 🤗


This post was originally published on my website at alexandersandberg.com.

Top comments (14)

Collapse
 
alvaromontoro profile image
Alvaro Montoro

In the past, IDEs were more rigid and less dynamic, but modern IDEs can be configured to convert tabs to spaces automatically when opening a file, and the same thing can be done the other way around (spaces to tabs). Also the code can be unified when committing/pushing it into the repository. By doing that, the tabs/spaces issue is really not an issue.

Collapse
 
alexandersandberg profile image
Alexander Sandberg

I agree. Modern tools help us, no matter what "side" we choose!

But we should assume that not everyone is aware of, or is able to use this functionality. Therefore, it's still important to think about 'accessible first', which, in this context, means using tabs.

Accessibility shouldn't be an add-on, it should be a default. 🙂

Collapse
 
ghost profile image
Ghost

Accessibility as default is nonsense. Accessibility imply access for different needs, sometimes opposed, of course should be a add-on, an easy access add-on but an add-on nontheless; are you suggesting that every editor readout loud by default and have huge fonts with high contrast by default? we should also have by default the OS in all languages?. The default is almost by definition for most of the target user, which doesn't mean accessibility shouldn't be a available and/or hard. But definetely not the default. If you want 1 single space indent because your lines are too long, the write longer lines, a 120 char line is way better than a single space indent, 4 spaces are too few and is hard to read? then use the Linux Kernel style with 8 or look for a tool to help your particular needs; a tab looks like a bunch of spaces, that's it, visual symbols main purpouse is to express something and just one "something". You have vertical delimiters for indents, coloured indents to make them easier to distinguish, you can enlarge space between characters. Newsflash, JS is not always available or desirable, should we disabla all JS by default? and high contrast hurt my eyes but are needed for others, so how do you propose to make both defaults?

Collapse
 
alvaromontoro profile image
Alvaro Montoro • Edited

I'm all for Accessibility and think it should go first, but this is not a matter of Accessibility being an extra/add-on or not. Most likely the tools that are being used already have these accessible features out of the box and can be set as the default (VSCode even detects when a screen reader is running and suggest changes to improve the experience on the fly!)

Thread Thread
 
alexandersandberg profile image
Alexander Sandberg

Didn't know VS Code had those features. That's really cool!

Yes, most likely, but not guaranteed. 🙂 Not everyone is using VS Code, Atom, or any of the other tools that have these kinds of features, but if we default to using tabs, it doesn't matter.

I guess the point I was trying to make is that, in an ideal world, everything should be designed for everyone. People with disabilities should not have to rely on certain tools or features.

Even though that's practically impossible, we should still aim for it, and make the default environment as accessible as possible.

Collapse
 
bgbruno profile image
BG

yap freedom from ^coder code design is most important for coding

Collapse
 
ward profile image
Davis

Tabs, that's it.

Collapse
 
alexandersandberg profile image
Alexander Sandberg

What's your current preference for indentation? Tabs or Spaces?

Would you consider switching to Tabs after learning this? 🙂

Collapse
 
ximias profile image
Alex Holberg

I don't really care. I hit my tab button on my keyboard for indentation, and the IDE takes care of the rest regardless of indentation character.
Come to think of it, I usually just hit my enter key, and the indentation is already made for me :D

Knowing this, I might start advocating tabs in the future, though.

Collapse
 
alexandersandberg profile image
Alexander Sandberg

Yes! The Enter key is often taking care of everything anyway!

If you don't really have a preference, all the amazing developers out there in need of customizable tab-widths will thank you for choosing tabs. ☺️

Collapse
 
voidjuneau profile image
Juneau Lim • Edited

Wow, I have never think about this issue at all. Thank you for enlighting me.

Used to use 4 spaces, however, I am going to figure out how I can set up my working environment.

Collapse
 
alexandersandberg profile image
Alexander Sandberg

Thank you for sharing, Juneau!

I was a tabs-dev for so long until I decided to try out 2 spaces instead, a few months ago. I didn't really think much of it until I came across Chase's post. Now I'm all for tabs again! 🙌

Collapse
 
swiftninjapro profile image
SwiftNinjaPro

I agree, tabs are better because of smaller files.

When you add up hundreds, or thousands of tabs, spaces would multiply that by 4.
100 tabs = 400 spaces.
1000 tabs = 4000 spaces.
1 million tabs = 4 million spaces.

you can reduce the file size to -3000 bytes by using tabs instead of spaces.
In the case of 1 million, your replacing 4000kb with 1000kb, simply by using tabs instead of spaces.

Of course, if you minify the final code, this only matters for space on your own PC, or if you have a team, it saves space on their PC. Also saves space on github, if you upload the original code.

Collapse
 
overengineered profile image
Juozas Kontvainis

I agree that accessibility is a concern in tabs vs spaces debate. I even tried using tabs about 6 years ago. It wasn't a great experience. Code in IDE looked fine. However I don't just look at my code in IDE - source control GUI app, git management web interface (my workplace wasn't using GitHub) all rendered tabs assuming 8 space indentation. So the result was accessibility issues even for individuals without special accessibility needs. In the ideal world tabs would be the best choice - the tools I was using would be easily adaptable for individual needs. In the real messy world the tools were developed with time constraints and did not have easy options to change the rendering options. So while I agree that tabs are best in principle, choosing spaces can be more practical, even when considering accessibility.