How Browsers Render HTML And CSS
I've read many articles online about how the Browser and CSS work together. Some say the Dom connects them. Others claim CSS is a computer language. Others will say the HTML and CSS are connected by the Parser before being rendered together. Many developers have fallen to misunderstanding and believe in mythical ideas. I will go into great detail and explain how they actually work.
The Browser
The secret to how the Browser works is key in understanding documents and how they store data both visually and hidden. But realistically it's still kept secret by many companies and the individuals who developed them.
The Canvas
Browsers Build a Document Page View by Requesting then Parsing the Dom ObjectModel or (HTML) and render them onto the Canvas. The Canvas uses screen positions called Pixel Coordinates. They begin at (x1 , y1) upper left corner and ending at (x2 , y2) at the bottom right hand corner. And scroll down the page based on height and length of the Document. And do this in numeric pixel order as shown below:
(left, top, right, bottom) or (x1, y1 , x2, y2) or (0, 0, 1366, 768) if your on a desktop.
The Mosaic Canvas
Microsoft Windows licensed a copy to create IE but claim they never used it. Netscape created the Navigator. Both had, modified and created two customized versions of the original NCSA Mosaic Canvas. Microsoft had been testing with Tk until Mosaic was born. Here are key functions that all Canvas perform:
- Draw squares, rectangles, circles, lines, archs etc.
- Set Text, Fonts, Font Size, Color foreground and background
- Set Images
- Set Frames or Windows
- Set Labels, Buttons, Entry Widgets etc.
- Set Colors
- Set Positions Using Coordinates
- Set Event Listeners on the canvas for Events from mouse or keyboard input
Here are the Tag Methods:
- tag_add Text Data
- tag_bind Event Bindings
- tag_config
- elide Designed for Div tags to be placed Invisible/hidden as dividers
- bbox Div encloses all other tags between it for placement or attributes
- tag_raise
- tag_lower
- tag_move Moves tag or tags used with tag_config
- insert Knows where the last object was placed on the screen
- index Knows where the last character of text was placed on the screen
- There are many more.......
The Parser
Parser's take the Dom Object or HTML and fetch all the data found both inside and in between HTML tags. The most vital of this sequence is to get first the CSS Style Sheet links, image paths and JS paths to request them. Then at the same instance the text is stored in many arrays or manageable List as Python calls them to be used for markup conversions in for loops.
The Parser To Canvas Markup
The Html Tags staged in a tree structure are Parsed for both identification class and id names (and these are the add_tag names) for the string data between them. The Parser then passes them to the Tokenizer where they are broken down into canvas markup. Then using the Canvas tag_add() function it adds all the text data one by one onto the canvas. The CSS canvas markups using a tag_config() function follow below them and set all the attributes for the already present HTML tag_add() functions updating them to render the page. The CSS is done before the Hyperlinks so the Event Positions wont change by the tag_config, tag_bind and bbox() methods.
The Canvas Render
In order
- All Text, Images, Buttons, Labels, Frames, Windows are Tagged and added to the canvas
- Then the Tags are Configured by attributes markup for colors, fonts, sizes bg and fg
- Then bboxed for all Divs, moved into position with all the tags in between them
- And finally the Binding Tags for Hyperlinks Events are added last to ensure their positions has not moved by the bbox and can be detected by the Event Listeners by position
- Page is rendered
Canvas Markers
One more trick up the Canvas methods sleeve. Yes the add_mark, config_mark and more are also added into the mix. These set markers are for You Guessed It--"For Copy and Paste events, Printers and Language Translations" also called Sentinels or simply Marks.
HTML And CSS Facts
Html and Css actually are not directly connected in any way. Because the only thing that they share in common is only the Entity tag names. And when the Canvas receives the markup tokens from both it actually does not combine them either. It only renders what the CSS markups tell it and coincidentally the Canvas Tags match their Config Tags that were already placed beforehand. And that is all it cares about to bring you your View.