59

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.

  • The HTML format looks ok for me. I don't see how is your format preference. Maybe you should add it. – nanda Feb 06 '11 at 10:39
  • 6
    yup, you're right. That's the default behavior for the HTML editor in Eclipse. To me that's a bug that should resolved. – flai Mar 03 '11 at 10:54
  • 1
    No, problem still exists with Indigo and Juno. Not sure about Kepler. – Tom Feb 22 '14 at 00:21
  • Still an issue in 2018, I guess the best solution is to use a different tool – user1133275 Dec 12 '18 at 18:10

5 Answers5

69

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.

Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108
prasad vsv
  • 1,138
  • 8
  • 10
  • `CTRL+Shift+f` works for me in LiClipse, However, it removes some `xhtml` compatibility such as `
    ` it make it `
    `
    – SaidbakR May 04 '16 at 01:37
  • 2
    This path still exists in Eclipse Neon, thanks looking for this for a LONG time – Captain Fantastic Aug 27 '18 at 18:09
  • span is not in the list but still is forced on one line :( – tibi Sep 11 '18 at 13:17
  • In 2018-12, auto format will not indent `head` and its child elements. Also doesn't indent `body`. By default, these elements are not declared as inline. – James Feb 08 '19 at 21:22
  • Same issue (for my POV it is not a normal thing to inline an input or a label in p for instance...) in Eclipse IDE for PHP Developers Version: 2020-03 (4.15.0). I don't understand why the default formater settings are such a mess... Thanks for the path of the preferences. – CodeKiller Apr 11 '20 at 15:11
2

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

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

That's what did it for me.

1

http://eclipsetidy.sourceforge.net/

You can specify your formatting preferences too: http://eclipsetidy.sourceforge.net/?act=preferences

Mike G
  • 4,713
  • 2
  • 28
  • 31
0

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.

Aaron Bono
  • 107
  • 1
  • 4
  • 4
    You mean it doesn't handle empty tags? An HTML formatter that didn't handle tags would be ... not an HTML formatter. – David Conrad Aug 02 '12 at 15:07
  • 3
    Using Juno, I don't see anything wrong with formatting of empty div tags. However, it does left-align everything that's not inside a body tag (i.e. the head and body tags are left aligned, despite being inside the html element, plus every item inside the head element). This isn't the way I like it, and I can find no option to change that. – user4815162342 Sep 01 '12 at 15:43
-3

CTRL+SHIFT+F works fine.

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

zx485
  • 28,498
  • 28
  • 50
  • 59