Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode adds spaces inside HTML tags inside React code

Starting to learn React from ground when I saved the code below VS Code formatted it as in the image.

ReactDOM.render(
    <div>
        <h1> Hi there  {name} </h1> 
        <p>  your lucky number is {num} </p>
    </div>,
    document.getElementById("root")
);

Line breaks with spaces formatted sample code from VSCode: enter image description here

I've googled it but some time later I realized that it was the file format that caused this problem.

Thanks Guillermo, the VSCode extension JS-CSS-HTML Formatter was the cause, uninstalling it and using prettier instead solved the problem.

like image 699
bbgo Avatar asked Oct 14 '25 08:10

bbgo


1 Answers

I solved by the following steps:

  • Install the Prettier-Code formatter.
  • Disable the default HTML formatter in settings.
  • After that restart your VS-Code.

For more detail please view the under link:

How to disable the default HTML formatter.

like image 144
Darren Zhang Avatar answered Oct 17 '25 01:10

Darren Zhang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!