An Explanation
Consider the HTML page on your browser as being composed of three key components:
- DOM (Actual HTML elements)
- CSS (Rules used by browsers to determine styling for #1)
- JavaScript (Language understood by browsers for manipulation of #1 and #2, as well as other dynamic tasks)
In regards to your question #1 about mixing these components, it is possible because all three are eventually integrated in the browser to form what you refer to as a 'page.'
It's helpful to view the progression from #1 > #2 > #3 as an enhancement of the page.
HTML and CSS should not be considered programming languages, so they are not merged together.
HTML functions as specifications to define page elements.
CSS serves as rules dictating element display.
JavaScript is the sole programming language within this trio, used for modifying behavior, display, and interactions.
All three work in conjunction to achieve desired user experience on a webpage.
Browser Utilization
Upon entering/clicking a URL, the browser requests content from the server, which responds with an initial HTML page containing DOM, CSS (via link tags), and JavaScript (via script tags).
The browser reads the HTML to construct a content tree
.
Next, it applies CSS to the content tree
to create a render tree
with style information added.
A layout
process assigns physical window coordinates to HTML elements.
Finally, everything is rendered visually on the page.
JavaScript is parsed separately via <script>
tags, allowing it to modify the DOM, alter CSS application, and initiate network calls.
Refer to this diagram illustrating the process for WebKit browsers (source)
https://i.stack.imgur.com/B3R8w.png
For further details on this process, check out this informative Article.
About File Extensions
Regarding your question #2 regarding the use of .html
extension, technically it merely stems from operating system file systems, something browsers themselves do not concern themselves with! Browsers primarily focus on mime-types sent by web servers, such as text/html
or image/png
, which dictate how browsers behave towards different types of content.