Skip to main content

Validate HTML as XHTML in Intelij

When working in intelij with HTML, sometimes we need to make sure our HTML is XHTML compliance, no un ened tags etc.
i.e. we should not have

<img src="myimage.jpg>

If You put above code in an HTML and run it in browser it will work fine, but if you are using some server side framework like Thymeleaf with Spring, it will generate error saying <img> tag must be terminated.

By Default intelij will not complaint about this and when you are writing HTML you may ignore the error and will get the error when you actually run it with in server. Or worst some HTML developer is writing the code HTML code for you and then you will have to fix all these errors.

Intelij can help you to make sure you write a valid HTML(XHTML). You can enable XHTML validation for HTML files by following below steps.

  • Go to Settings(Windows)/Preference(mac) in Intelij.
  • Search for "File Types"
  • Find HTML as shown in image below. You will see HTML has some extension associated with like *.html, *.htm etc

  • Now find XHTML and it will look like this 

  • Click "+" button under "Registered Patterns" and add *.html.
  • It will give following warning, please continue and click on "Reassign Wildcard"

  • Press "ok", Reopen your html file.
  • Right click an HTML file ans click recompile.
  • It will show you error on each line which are incorrect, go and fix them :)