Usually browsers like chrome and firefox will take care of this. In case of you want to check HTML structure, you will have to first get HTML source using
String html = driver.getPageSource();
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);
if (doc.ParseErrors.Count() > 0)
{
//Invalid HTML
}