They carry a lot of Google advertising, and Google consistently ranks them (as you've noticed) at the top of search results for any query connected with html, css, etc. More reputable sources, that happen to not carry Google advertising, are ranked lower in the search results.
Google employees have participated in threads here, claiming that search result ranking is not influenced by revenue for Google, and that W3School's persistent high ranking is because, somehow, it's a better result for users. When people here have pointed out how poor the site is and how much better other sites are, the Google employees acknowledge that there seems to be something to that and that there might be a "bug" and will pass on the information inside the company. But, as you've seen, W3Schools is still on top.