Every programming language, like a markup language (HTML), follows certain rules that need to be observed. The same is true of HTML.
The rules specify the style in which HTML code should be written and the structure the resulting code should have. Valid code is code that follows these rules.
With classic programming languages, if we do not follow the rules, the code usually cannot be run at all. HTML is different. The page is displayed, but with errors. Such code, however, is not valid. Modern browsers even have a feature that lets them correct errors.
Invalid code can, however, cause a big problem for example for disabled people who use some software that cannot correct the errors. Another reason to write valid code is older browsers, which cannot correct errors, and the page could be completely unreadable in them.
It is therefore a good calling card for every web page creator that the code they write is valid.
Anyone can check whether the code is written correctly (validly) using a so-called validator.