How does HTML work? Does it get parsed, compiled and then executed? Does it get converted to a high level language like C, C++, Python, `Java’, then the C code gets compiled and executed?
If this is the case then, why can’t we keep a code that is very close to architectural code, which can be interpreted by a virtual machine, as compiling and parsing has n^3 complexity.
If this is not the case then how does it work. How do browsers work?
None of those. It is parsed by the web browser and turned into (browser specific) internal data structures that are not source-code of any programming language. The browser then computes a screen layout and paints the screen based on that data structure. The component of the web browser that does this is known as the rendering engine; e.g. WebKit and Gecko are examples.
The details are complicated, but many web browsers are open source so you can examine the source-code to see what is really going on.