59

I hear the term "hard tabs" and "soft tabs" (often with much debate about which is better), but what do the two terms actually mean? I am looking for a simple definition of "soft tabs" and "hard tabs".

2 Answers 2

71

Hard tabs use the tab character, http://en.wikipedia.org/wiki/Tab_key#Tab_characters

Soft tabs are just spaces. Soft tabs are usually either 2 or 4 spaces, depending on convention.

If you set your editor to use "soft tabs," when you press the Tab key on your keyboard your editor will insert spaces instead of the tab character.

10

Hard tabs are the equivalent of using the tab key to tab your code while soft tabs are spaces added in to emulate a tab either manually or via a code editor like Sublime Text. There are some who believe that soft tabbing is better for readability for larger teams that use different text editors since some editors will give different spacing for hard tabs, but I think you can use either one as long as you stick to one and use it consistently. In the end, this mostly comes down to personal preference.

1
  • 2
    This answer confuses the tab key and the tab character. Soft tabbing also uses the tab key to tab your code.
    – Phil
    Mar 18, 2020 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.