Skip to main content

Command Palette

Search for a command to run...

How a Browser Works

Published
•2 min read•View as Markdown
How a Browser Works

what happens after i type a url and press enter

this question looks simple
but inside browser full movie is running

browser is not magic
it is system

let us see flow with pictures


high level browser architecture

browser has many parts
each part has one job

https://miro.medium.com/1%2A35CqQzWdC2NaFQA3X4749g.png

think like this

user interface talks to browser engine
browser engine controls everything
networking brings data
rendering engine draws page
js engine runs logic

team work


user interface part

this is what we touch daily

address bar
tabs
buttons

https://beehiiv-images-production.s3.amazonaws.com/uploads/asset/file/e525ea1b-f275-45e2-bd83-cb6725583b22/bb4ed1cf-6143-48b5-b9af-60f65d921e68_500x339.png?t=1651893384

https://www.grantscourses.co.uk/images/addressBar.jpg

when you type url
this part sends message inside browser


browser engine vs rendering engine

this part confuses many beginners

https://web.dev/static/articles/howbrowserswork/image/webkit-main-flow-b779d50c0cf28.png

browser engine is like manager
rendering engine is like painter

browser engine says
go fetch data
go draw page

rendering engine actually draws


networking how browser fetches files

browser needs files from internet

https://media.licdn.com/dms/image/v2/C4D12AQGy5TDVq9WX8A/article-cover_image-shrink_720_1280/article-cover_image-shrink_720_1280/0/1642449980579?e=2147483647&t=mtVKk1xuSKVu8n5KMwKa9a8lxbmzdTG47F_sEmfPUvI&v=beta

https://www.researchgate.net/publication/311571526/figure/fig3/AS%3A438170157359106%401481479314691/HTTP-request-response-model.png

browser sends request
server sends response

html
css
js
images

networking is delivery system


html to dom creation

html comes as text
browser converts it into structure

https://upload.wikimedia.org/wikipedia/commons/thumb/5/5a/DOM-model.svg/1280px-DOM-model.svg.png

dom is tree

html is root
elements are branches
text is leaves

easy to manage


css to cssom creation

css also parsed

https://miro.medium.com/0%2AFp3mesmVsWB7z0OD

cssom stores styles

color
size
font
position

browser keeps it separate from dom


dom plus cssom makes render tree

now magic happens

https://web.dev/static/articles/critical-rendering-path/render-tree-construction/image/dom-cssom-are-combined-8de5805b2061e.png

https://media2.dev.to/dynamic/image/width%3D800%2Cheight%3D%2Cfit%3Dscale-down%2Cgravity%3Dauto%2Cformat%3Dauto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F56cdizmlhcvpwgjx55k7.png

dom says what
cssom says how

render tree knows
what is visible
what is hidden

only visible things go ahead


layout reflow paint display

final steps before screen shows page

https://blog.openreplay.com/images/how-browser-rendering-works-and-why-you-should-care/images/hero.jpg

https://i.sstatic.net/PWEik.png

layout decides size and position
paint fills colors and text
display shows pixels

this happens many times when page changes


parsing explained with simple example

parsing means breaking into meaning

https://runestone.academy/ns/books/published/pythonds/_images/meParse.png

2 + 3 * 4

system creates tree
multiplication first
then addition

same logic browser uses


full browser flow from url to pixels

complete story in one view

https://media2.dev.to/dynamic/image/width%3D800%2Cheight%3D%2Cfit%3Dscale-down%2Cgravity%3Dauto%2Cformat%3Dauto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fnmgeburj0q5o1vazjkxr.png

  • type url

  • network fetch

  • html to dom

  • css to cssom

  • render tree

  • layout

  • paint

  • display

this is browser life cycle