Indentation Rules for CSS / html / javascript

Is there a preferred set amount when it comes to:

CSS / html / javescript

I find this to be good and useful for indention purposes:

Should html be set to tabs

javascript should be set to 4 spaces.
I only say 4 because that’s how jslint likes it.

And CSS should be

The debate about tabs Vs spaces has been running a long time, long before this recent topic:-

While the answer may just be “use which you personally prefer”, I think most can agree on this: Do always use proper indenting in one form or another to make code more readable and be consistent in your chosen style of indenting.

4 Likes

Thank you for that, I will take a look at it now.

Many people are obsessed with the spaces vs tabs wars. Luckily, I do not have to worry about indentation while writing my codes.

I leave the work to my IDE. :slight_smile:

PyCharm(IDE) has an auto-indentation feature that helps you organize your code properly. It saves you lots of stress. Imagine having an HTML file of over 500 lines? One could have nightmares indenting the lines of the file.

With PyCharm just press “Ctrl + Alt + L” on your keyboard and see the auto-indentation magic!

I’m pretty sure other IDEs will have their own way of doing this.

DreamWeaver has an annoying habit of indenting curly braces in the fashion that most people prefer. Unfortunately, I don’t like that format, and get annoyed every time.

For example, when working in JavaScript, I prefer:

function myFunction(){
    .. my code
    }<!-- closing brace indented -->

But every time I type the closing curly brace in DW, I get:

function myFunction(){
    .. my code
}<!-- closing brace not indented -->

So I have to use the left arrow key and tab to get it where I like it. AFAIK, there is no way to change this; only to turn off auto-format, which would also be a pain, IMHO.

V/r,

^ _ ^

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.