Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format html code in Visual Studio Code such that attributes are on separate lines?

There seems to be a lack of formatting settings for vscode. I want to be able to format html such that my html shows up as:

<div attrib1=value1      attrib2=value2      attrib3=value3>   Content </div> 

This is one functionality that I'd really love to have!

like image 276
Siddharth Singh Avatar asked Nov 06 '15 05:11

Siddharth Singh


People also ask

How do I beautify a HTML file in Visual Studio Code?

To improve the formatting of your HTML source code, you can use the Format Document command Ctrl+Shift+I to format the entire file or Format Selection Ctrl+K Ctrl+F to just format the selected text. The HTML formatter is based on js-beautify.

How do I use code formatting in Visual Studio Code?

VS Code has great support for source code formatting. The editor has two explicit format actions: Format Document (Ctrl+Shift+I) - Format the entire active file. Format Selection (Ctrl+K Ctrl+F) - Format the selected text.

How do you align all codes in VS code?

On Windows Shift + Alt + F. On Mac Shift + Option + F. On Linux Ctrl + Shift + I.


1 Answers

VSCode added a way to do this now. You can edit your settings.json (ctrl+shift+p) and then add the following for the desired effect:

"html.format.wrapAttributes": "force-aligned" 

--or--

"html.format.wrapAttributes": "force" 

force-aligned will also add indents to align it with the attribute on the line where tag was opened.

Visit this link for more details or updates.

like image 114
Siddharth Singh Avatar answered Oct 06 '22 01:10

Siddharth Singh