Code indentation spacing standardization

Asked

Viewed 2,346 times

6

Used Sublime Text for the front-end, I already had to open some old codes and I had problem with indentation. I saw that it was only to modify the tab size.

I wonder if there is a Tab Size standard for building the HTML of a site. I currently use Tab Size 4.

  • 1

    In this case, "tab-size" is the size of the "tab". It is not the same thing of size or indentation spacing, which can also be done through spaces.

  • It is important not to let your IDE write in soft tab

2 answers

4


There are several patterns. The most common is the identation with 4 spaces.

I recommend the Google HTML/CSS Style Guide as standard for HTML and CSS.

Indentation

Indent by 2 Spaces at a time. Don’t use tabs or mix tabs and Spaces for indentation:

<ul>
  <li>Fantastic
  <li>Great
</ul>
.example {
  color: blue;
}
  • 2 spaces seems ideal, really.

  • Personally I don’t like it, I think it all gets very sticky. Without a real IDE it is even difficult to parse a poorly constructed HTML.

  • In the end, it’s worth whatever the team plans and take to the end. I usually make the controller deliver compressed HTML, so identation only matters to developers

3

DEPENDS A LOT ON coding standards application (or layout as is your case) and still programmer.

Some leftists defend the use of TAB because it is somewhat universal, but this is counter-argued by the right wing who defend the use of spaces (usually 4) because TAB is susceptible to the application that interprets it as a "large space". but the counter-counter spaces argued with the fact that, programmatically, a TAB occupies less physical space than 4 common spaces.

Most apps define a TAB as something between 2-3cm. Others more, others less.

The least you can do is set up the IDE the way you’re used to at least having a comfortable visual experience. If the application does not support, make a regular global overwrite before starting and after it finishes from one format to another.

  • Thank you very much for your reply. Can you tell me what the default of browsers is? For when I view, for example, the HTML in Chrome, it has an uncomfortable spacing.

  • 1

    I don’t think browsers interfere with that. If the code that originated the HTML has fractionated the other elements (common in spaghetti code that mixes elements of the server language with output) resulting in many consecutive blank lines, non-standard spacing and etc. the browser maintains. However, there are some browser extensions that fix this, such as Firefox’s Htmltidy

  • @Brunoaugusto , this is very common in frameworks, where output html is dynamic.

  • @Marceloaymone I know that, but I think so, if the framework will, directly or indirectly, mess up the output HTML, why not try to fix it? The issue of indentation could generate a Overload terrible for application, but the duplicated blank lines is solved with a simple ER. And there’s also the programmer’s side that at the time he’s creating the template could very well use more or less spaces than it should for the output out cute. At least I’m neurotic to that point. : P

  • 1

    Look at the source of Uol and you will be sad. eheheh On the blank lines, I find unacceptable. About the spacing zerar, I think normal and do not bother much with this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.