How to format html files in Eclipse?

EclipseCode FormattingEclipse Wtp

Eclipse Problem Overview


The XML formatting works perfect but not the html formatting. In fact if I use "cmd-shift-F" for a html file, it just left aligns almost everything. I've attached the before and after pictures.

No eclipse html formatting applied

After eclipse html formatting applied

Does anyone know how to fix this? I played around with HTML formatting preferences but had no luck. Note that the same document, if it is saved as xml will format perfectly.

I am using eclipse 3.6 with WTP plugin.

Eclipse Solutions


Solution 1 - Eclipse

go to Window --> preferences --> Web --> HTML files --> Editor.

In the Inline Elements section, select all the elements that you don't want eclipse to inline(continue with same line).

Click Apply and then Ok. Now re format using ctrl + shift + f.

Solution 2 - Eclipse

go to Window --> preferences --> Web --> HTML files --> Editor.

Make sure "Indentation Size" is not set to zero.

That's what did it for me.

Solution 3 - Eclipse

Solution 4 - Eclipse

Eclipse Juno release seems to do a good job. It doesn't handle

tags (that is the div tag that closes itself). Not sure why anyone would use it but we have a project that has them sprinkled about, probably from some WYSISYG editor someone was using.

Solution 5 - Eclipse

CTRL+SHIFT+F works fine.

Just click on the source codes you want to format and then press CTRL+SHIFT+F.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser308808View Question on Stackoverflow
Solution 1 - Eclipseprasad vsvView Answer on Stackoverflow
Solution 2 - Eclipseuser3888750View Answer on Stackoverflow
Solution 3 - EclipseMike GView Answer on Stackoverflow
Solution 4 - EclipseAaron BonoView Answer on Stackoverflow
Solution 5 - EclipseFidele FisonView Answer on Stackoverflow