How do I format and clean up messy code automatically?
You'll be able to: Auto-format document in VS Code
- Risk
- Safe to try
- Windows
- Windows 11 · Windows 10
Filed under Programming & tools
The steps
- 1
Open the file containing the messy or unaligned code in Visual Studio Code. Your code file is open in the main editor window with visible text lines.
What is code formatting?
Formatting cleans up tabs, indentation, braces, and line breaks so your code follows clean industry standards and is easy to read.
- 2
Press ShiftAltF together on your keyboard. The editor instantly aligns all indentations, spaces, brackets, and line wraps across the whole file.

- 3
If a popup at the bottom asks to select a default formatter, click your preferred formatter (such as Prettier or the built-in language formatter). VS Code remembers your choice and will format automatically using that tool from now on.
- 4
Press CtrlS to save your freshly formatted code. The file is saved with clean, professional alignment.
It looks different on my screen
You can also format your file by right-clicking anywhere in the code editor and selecting Format Document.
Did this work?
Updated 2026-08-24اقرأ بالعربية