To comment out multiple lines in Visual Studio, select the lines and press Ctrl + K, then Ctrl + C. To uncomment them, select the lines and press Ctrl + K, then Ctrl + U. You can also use Edit > Advanced > Comment Selection, or the comment buttons on the toolbar. In Visual Studio Code, the shortcut is Ctrl + / (Command + / on a Mac).
Visual Studio uses the right comment style for each language, like // for C# and JavaScript or ' for Visual Basic. Here are all the shortcuts, plus block comments and how to change the keys.
Visual Studio comment shortcuts
| Action | Visual Studio (Windows) | Visual Studio Code |
|---|---|---|
| Comment selected lines | Ctrl + K, Ctrl + C | Ctrl + / (toggle) |
| Uncomment selected lines | Ctrl + K, Ctrl + U | Ctrl + / (toggle) |
| Toggle line comment | Ctrl + K, Ctrl + / (Visual Studio 2022) | Ctrl + / |
| Toggle block comment | Ctrl + Shift + / (Visual Studio 2022) | Shift + Alt + A |
| On a Mac | N/A | Command + / and Shift + Option + A |
How to comment multiple lines in Visual Studio
- Select the lines you want to comment. You don’t need to select entire lines. Any part of each line works.
- Press Ctrl + K, release, then press Ctrl + C.
Or use the menu: Edit > Advanced > Comment Selection.

Use the toolbar buttons
The Text Editor toolbar has Comment out the selected lines and Uncomment the selected lines buttons. If you don’t see them, go to View > Toolbars > Text Editor.
How to uncomment multiple lines
- Select the commented lines.
- Press Ctrl + K, then Ctrl + U. Or choose Edit > Advanced > Uncomment Selection.
Block comments
For languages like C#, C++, and JavaScript, you can wrap code in /* and */ to create a block comment. In Visual Studio 2022, select the code and press Ctrl + Shift + / to toggle a block comment. Line comments (//) are usually easier to add and remove.
How to comment in Visual Studio Code
- Select the lines.
- Press Ctrl + / to comment them. Press it again to uncomment.
- For a block comment, press Shift + Alt + A.
You can also use the Edit menu > Toggle Line Comment or Toggle Block Comment.
How to change the comment shortcut
- Visual Studio: Go to Tools > Options > Environment > Keyboard, search for Edit.CommentSelection, and assign a new shortcut.
- VS Code: Press Ctrl + K, Ctrl + S to open Keyboard Shortcuts, then search for “comment.”
More questions about commenting code in Visual Studio
Why doesn’t Ctrl + / work on my keyboard?
On some international keyboard layouts, the slash key is in a different place or needs Shift. Change the shortcut in your keyboard settings as shown above.
Does commenting code delete it?
No. Commented code stays in the file but is ignored when the program runs.
When a build crashes outside the editor, turning on Just-In-Time debugging lets Visual Studio open at the failing line.
Can I comment out code in XAML or HTML?
Yes. Visual Studio uses <!-- --> automatically for markup files when you press Ctrl + K, Ctrl + C.

Kermit Matthews runs Live2Tech from just outside Philadelphia. He is an IT specialist with over 20 years of experience, from a university help desk to small-business IT, IT management and his own consulting practice, and has written tech guides full time since 2020. Steps are checked against the current software on a real device or the maker’s official documentation. More about Kermit.