Search code examples
htmlvisual-studio-codeformattingprettier

How do you stop Prettier in VS code splitting attributes onto multiple lines?


I am using prettier to format my code in VS Code but I really dislike how it does it.

My main beef is it splitting attributes over multiple lines.

<input
    type="checkbox"
    name="asiaNews"
    id="asiaNews"
    value="asiaNews"
/>

I'd much prefer it to look like this

<input type="checkbox" name="asiaNews" id="asiaNews" value="asiaNews" />

I can't find anything in the docs or on SO

How to prevent VS Code from breaking up long HTML lines into multiple lines?

Is there a way to do it or a different tool that I can use so I can have my own custom formatting rules that suits my sensibilities?


Solution

  • A quick fix is to go to Prettier Extension Settings (ctrl + shift + X) and in Prettier Extension Settings search for "Print Width" set it to 250 or anything that works for you.

    1: Go to Extention Settings:

    Prettier Extension Settings

    2: Change the value of Print Width to your liking.

    Changing the value of Print Width

    To disable format code on save. Turn off the "Format On Save" and use Alt+Shift+F to format the code when ever you want.

    Disable or enable Format On Save

    You can visually check the setting here