From Request to Rendering: The Journey of an HTML File

Jino R Krishnan
8 min readFeb 19, 2023
Photo by Patrick Fore on Unsplash

Welcome to our blog post on the journey of an HTML file from request to rendering! If you’re reading this, chances are you’ve interacted with countless web pages on the internet, each with its own unique design and content. But have you ever wondered how your browser is able to take the HTML code that makes up a web page and turn it into a fully functional, interactive experience on your screen? In this post, we’ll dive into the step-by-step process that browsers use to retrieve and display HTML files, giving you a better understanding of the inner workings of your web browser.

Well, the basic steps involved in how a browser works when we open an HTML file are:

User opens the browser: The process starts when the user opens a web browser on their device, such as Google Chrome, Firefox, Safari, or Edge. Once the browser is opened, the user can type in the address of the website they want to visit or click on a link to open a webpage.

Browser resolves the domain name: The browser then looks up the domain name of the website using the Domain Name System (DNS) to find the IP address of the web server that hosts the website. If the domain name is cached locally in the browser, the browser can skip this step and proceed to the next step.

Browser establishes a TCP connection with the web server: Once the IP address of the web server is obtained, the browser establishes a Transmission Control Protocol (TCP) connection with the server on port 80 or 443, depending on whether the website is using HTTP or HTTPS.

After establishing the TCP connection, the browser sends an HTTP request to the web server for the specific webpage that the user wants to visit. The request includes the type of request, the URL of the webpage, and any additional headers.

The web server then processes the request and sends an HTTP response back to the browser. The response includes the HTML code for the webpage, as well as any additional files, such as stylesheets, JavaScript files, and images that are needed to display the webpage.

Browser parses and renders the HTML file: Once the browser receives the HTML file, it begins to parse the file to build the Document Object Model (DOM) tree, which represents the structure of the webpage. The browser then applies the CSS styles and JavaScript code to the DOM tree to create the final layout and functionality of the webpage. Finally, the browser renders the webpage on the screen, and the user can interact with the webpage using the mouse, keyboard, and touch gestures.

User opens the browser

The process of opening a website in a web browser usually starts with the user deciding which website they want to visit. This can be done in a number of ways, such as following a link from another website, typing the website address (also known as the URL) into the address bar of the browser, or using a search engine to find the website.

Once the user has decided which website they want to visit, they open their favorite web browser on their device, such as Google Chrome, Firefox, Safari, or Edge. The browser is a software application that enables the user to access and display web pages on the internet.

To navigate to the website, the user types the URL of the website into the address bar of the browser. The URL typically consists of several parts, including the protocol (usually http:// or https://), the domain name (such as google.com or facebook.com), and the path to the specific webpage (such as /search or /about).

After typing the URL into the address bar, the user hits the enter key or clicks on the “Go” or “Search” button in the browser. This triggers the browser to start the process of requesting the website from the web server that hosts the website.

In some cases, the browser may suggest or autocomplete the website address based on the user’s browsing history or bookmarks. This can help to speed up the process of accessing frequently visited websites.

Overall, the first step of opening a website in a web browser involves the user deciding which website they want to visit, opening their favorite browser, typing the URL of the website into the address bar, and triggering the process of requesting the website from the web server.

Browser resolves the domain name

When the user types a website URL into the browser’s address bar, the browser needs to determine the IP address of the web server that hosts the website. This is done using the Domain Name System (DNS), which is a distributed system that maps domain names to IP addresses.

Here are the steps involved in resolving the domain name:

  1. Browser checks local DNS cache: The browser first checks its local DNS cache to see if it has already resolved the domain name recently. If the domain name is cached locally, the browser can skip the DNS lookup process and proceed directly to step 3.
  2. Browser sends a DNS request: If the domain name is not cached locally, the browser sends a DNS request to a recursive DNS resolver. The resolver is responsible for finding the authoritative DNS server for the domain name and requesting the IP address of the web server.
  3. Recursive DNS resolver sends a DNS request: If the resolver does not have the IP address for the domain name in its cache, it sends a DNS request to the root DNS server. The root server responds with a referral to the top-level domain (TLD) server for the domain name (such as .com or .org).
  4. TLD server sends a DNS request: The resolver then sends a DNS request to the TLD server, which responds with a referral to the authoritative DNS server for the domain name.
  5. Authoritative DNS server sends the IP address: The resolver sends a DNS request to the authoritative DNS server for the domain name, which responds with the IP address of the web server that hosts the website.
  6. Browser establishes a TCP connection: Once the browser has obtained the IP address of the web server, it establishes a TCP connection with the server on port 80 (HTTP) or 443 (HTTPS). This connection enables the browser to send an HTTP request to the web server to retrieve the HTML file for the webpage.

Browser establishes a TCP connection with the web server

Once the browser has established a TCP connection with the web server that hosts the website, it sends an HTTP request to the server to retrieve the HTML file for the webpage. The HTTP request typically consists of the following parts:

Request method: The request method is typically either GET or POST, which specifies the type of request that the browser is making to the server. The GET method is used to retrieve a resource from the server, while the POST method is used to submit data to the server.

Request URL: The request URL is the URL of the HTML file that the browser is requesting from the server.

HTTP version: The HTTP version specifies the version of the HTTP protocol that the browser is using to communicate with the server.

Request headers: Request headers provide additional information about the request, such as the user agent string (which identifies the browser and operating system that the user is using), the referrer URL (which specifies the webpage that linked to the current webpage), and any cookies that the browser has stored for the website.

Request body: For POST requests, the request body contains the data that the browser is submitting to the server.

Once the server receives the HTTP request from the browser, it processes the request and generates an HTTP response, which typically consists of the following parts:

Status line: The status line includes the HTTP version, the status code (which indicates whether the request was successful or not), and a brief description of the status code.

Response headers: Response headers provide additional information about the response, such as the content type (which specifies the type of data that the server is sending), the server software (which identifies the web server software that the website is running on), and any cookies that the server wants to set for the browser.

Response body: The response body contains the HTML file for the webpage that the browser requested. This file may also include additional resources, such as images, CSS files, and JavaScript files, which the browser will need to retrieve in order to fully render the webpage.

Once the browser receives the HTTP response from the server, it starts to render the HTML file for the webpage. This involves parsing the HTML file, applying any CSS styles that are defined in the file, and executing any JavaScript code that is included in the file. The browser also retrieves any additional resources that are referenced in the HTML file, such as images, CSS files, and JavaScript files, and renders them on the webpage as well.

Overall, the third step of how a browser works when we open an HTML file involves the browser sending an HTTP request to the webserver to retrieve the HTML file for the webpage, and the server responding with an HTTP response that includes the HTML file and any additional resources that are needed to render the webpage. The browser then parses the HTML file, applies any CSS styles, executes any JavaScript code, and renders the webpage for the user to view.

Browser parses and renders the HTML file

After the browser has finished parsing and rendering the HTML file and any additional resources that are referenced in the file, it finally displays the webpage to the user. The process of displaying the webpage involves the following steps:

Constructing the Document Object Model (DOM): The DOM is a tree-like structure that represents the HTML file and all of its associated resources. The browser constructs the DOM by parsing the HTML file and any additional resources that are referenced in the file. The DOM is what the browser uses to render the webpage.

Constructing the CSS Object Model (CSSOM): The CSSOM is a tree-like structure that represents the CSS styles that are applied to the HTML file. The browser constructs the CSSOM by parsing the CSS styles that are defined in the HTML file and any external CSS files that are referenced in the file.

Combining the DOM and the CSSOM to create the render tree: The render tree is a tree-like structure that represents the visual elements of the webpage, such as paragraphs, headings, images, and other visual elements. The browser combines the DOM and the CSSOM to create the render tree by applying the CSS styles to the HTML elements and determining their position and size on the webpage.

Layout: Once the browser has constructed the render tree, it determines the layout of the webpage by calculating the position and size of each visual element on the webpage.

Painting: After the layout has been determined, the browser finally paints the webpage by drawing each visual element onto the screen. This is done using the computer’s graphics hardware to ensure smooth scrolling and animation.

Once the browser has finished displaying the webpage, the user can interact with it by clicking links, filling out forms, and performing other actions. When the user interacts with the webpage, the browser sends additional HTTP requests to the web server to retrieve new resources and update the webpage accordingly.

--

--