r/vscode • u/Passerby_07 • Apr 20 '26
Is there a solution for this terrible comment toggling behavior for CSS in VS Code?
- When I press the comment toggle to try to disable/comment out the whole line, it enables/uncomments the description instead. Breaking my code.
- When I press the key again, it disables/comments out everything.
- When I press again, it enables/uncomments everything.
All I want is to toggle the statement without affecting my comment.
I want my comments inline and not on a separate line.
This is not an issue with other languages like JavaScript.
5
Upvotes
4
u/abrahamguo Apr 20 '26
Put the comment on a separate line - that’s the only solution.
4
u/Resident-Log Apr 21 '26
It probably doesn't work like it might in other languages because CSS comments cannot be nested (per MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Syntax/Comments).
So VS cannot comment out the whole line if that line already contains a comment.
While inline comments are usually put at the end of a line, they can be placed elsewhere within the line so it would be far more complicated to code it to add the opening and closing comment syntax appropriately for all possible circumstances not to mention to later appropriately revert that action.
1
u/Agreeable_Care4440 Apr 22 '26
Yeah this is a known CSS behavior in VS Code, it uses block comments (
/* */) so it tries to be “smart” and ends up toggling inner comments too.Workaround: use line comments via extension or manually comment like
/* property: value; */instead of mixing inline comments, CSS just doesn’t support true line comments like JS.