Basically localhost (or the IP address 127.0.0.1) is a way to make your computer do things your could usually only do with a server. 8000 is a port number (not to be confused with physical ports). It allows multiple devices to use localhost, similar to how an extension on a phone line lets multiple people make calls on one phone line. If you don't say a port number it will jus go to a default one.
Usually HTML doesn't need localhost, because it doesn't need a server. Localhost is mostly for using backend languages like PHP/Ruby/SQL on your computer. It seems a little odd to me for codecademy to use it for HTML, but I'm guessing codecademy is using Ruby to do some logic like checking your code for errors.