2

What goes behind the scene when a web browser is served with HTML content and it renders it?

For example, if the browser encounters, say, an <h1> tag, how does it first look for a style defined and if not goes for the default <h1> font style? Where/How is this default style defined?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Phi_1.618
  • 191
  • 1
  • 1
  • 7
  • 2
    I focused the question (title): I might have removed some desired information, but I feel that this will make the question able to "stay" on SO without being closed. (There are many "technologies" that are used in the entire process ..) –  Dec 24 '12 at 05:41
  • Browser dependent. They do have a default rendering style. You can see the clear difference from IE and chrome – SwiftMango Dec 24 '12 at 05:56
  • ^ Yes. Thats what the questions says. How has a default rendering style has been defined in a browser? How do we tweak the default rendering style of an open source web browser? – Phi_1.618 Dec 24 '12 at 06:04

3 Answers3

3

Browsers that implement CSS for rendering HTML make use of user-agent default stylesheets (which have a low precedence in the cascade making them trivial to override in your own CSS). This is how they obtain default styles for various elements in absence of an author stylesheet.

Some vendors provide the source code of their UA default stylesheets so you can look at them and see how exactly certain browsers style certain elements by default. You can find some links in this question.

Most browsers provide a user stylesheet feature, where you write CSS that applies to all Web sites (or only to specific sites, via the @document rule). This is where !important is commonly and acceptably used, as author styles (i.e. styles that come from Web sites themselves) will typically override user styles. You generally don't want to modify a browser's user agent stylesheet at all, even if it's open source, unless you're planning to fork it into something entirely new and you need to add styles that are specific to that fork.

As for how a browser looks for a style definition: that's a very broad question, but it mainly involves looking at each stylesheet as well as any inline style attributes and resolving the cascade and any other environmental constraints accordingly, so as to obtain a value that it can use for the actual drawing. The cascade itself is a semi-broad topic, and how exactly a browser parses CSS and implements cascade resolution is an implementation detail and therefore highly dependent on the browser you're looking at. If you're interested in the gory details, Tali Garsiel has an incredible write-up of the entire process of receiving and displaying a Web page.

Community
  • 1
  • 1
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
0

Think of Browsers as Language interpreter. Language over here are CSS, JS, HTML etc. So they have inbuilt engine to handle your html tags and render it appropriately as per specification.

rai.skumar
  • 10,309
  • 6
  • 39
  • 55
  • My question is precisely about the 'inbuilt engine to handle your html tags'. Can you give an example of a simple case of rendering a tag? – Phi_1.618 Dec 24 '12 at 05:55
0

As per my experience, I am ok with it. I shall also say for which targets tese CSS styles are supported with Flash and php.