VScode settings change for indentation

Hard to find a category for this one so I apologize if this is the wrong place. I searched through the VScode settings for a long time and tried editing the settings.json file but I don’t really know what the code for altering this setting would be in there.

I basically like to format my CSS code using indents similar to the way my HTML is indented. For example:

header {}
     h1 {}
     header.nav {}
          header.nav ol {}
               header.nav ol li {}
                    header.nav ol li:hover {}
     header.p {}
body {}

If I hit save, it all goes to left aligned.

This used to be great but I clicked reformat once on the CSS I guess, and while I don’t have a problem with my CSS being formatted besides this one issue, it is a bummer for me. I’m going to turn off CSS format on save if we cant find a solution here.

Hi there!

I am not aware of any settings that could inherently change how indentations work, but only how many spaces an indentation creates. (Which would affect every indentation, not per line)

Instead, what you could do is turn off formatting on save, paste, and typing. Just go to settings > search format > click formatting > and uncheck what you wish. However, this would disable formatting on all text editors. You would need to use the shortcut to format manually.

You could also disable formatting just in CSS by going to CSS instead of formatting when you search format and check the box.

I hope this helps. :slight_smile:

1 Like

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