Does Google Prefer Valid HTML?
No. While Google recommends we use W3C validation, Google doesn’t rank valid html and css pages above invalid pages. If Google can crawl and render a page Google will rank the page appropriately based on how relevant it is to the query. Invalid HTML can on the other hand can cause search engines problems.