Anton ☕

Today I Learned How To Change GitHub's Tab Size

March 05, 2020

By default, GitHub renders tabs as 8 spaces. For me, this is a pretty annoying default. I’m glad to have learned 2 ways to change this, one temporary, and another somewhat permanent.

Temporary Way

Use the ts query parameter on any page that renders code that has tab indents (ie. ?ts=2 or ?ts=4, etc.).

Doing so will render the tabs based on the length provided.


Permanent Way

There is no way to globally set this within your GitHub account. However, there is a way to set this per respository.

Use a .editorconfig file to set both the indent_style and indent_size.

indent_style = tab
indent_size = 4

GitHub is able to recognize the file and respect the settings provided when rendering files.


BONUS: Permanent Way #2

Another option for globally setting the tabs is to use a Chrome Extension.

Extensions like “Tab Size on GitHub” will change the tab size on any code page from the default of 8 to 4.

Take note that using a Chrome Extension might supersede the previously mentioned options since such extensions will most likely be injecting custom CSS.

Source: GitHub Cheat Sheet

Written by Anton Mata who lives and works in Manila building useful things. You should follow him on Twitter and GitHub