PRIVILEDGED ONES
Body Secrets
A good point to start our investigation into the dark secrets of the Priviledged Ones, is the first step in the hierarchy of elements: The masked, front man - code named "body", who appears to rule the presentation aspects (i.e. rendition) of a Web Page on the Screen, especially in the Quirks Age.
Let's proceed to see - as far as it is possible, what these "secret" powers and priviliges of this character are!
Before We Start
Each test page used in these experiments are:
- Stand-alone with an Internal Style Sheet
- In the Standards Mode (XHTML 1.0 Transitional)
When this study originaly started sometime ago, the following browsers/versions were used, since they were the most current versions at that time:
- Internet Explorer 6.0
- Mozilla 1.7
- Netscape 7.1
- Opera 7.54
However, due to other obligations on my part, I have not had much "spare time" to dedicate to this project. In the mean time different browsers came out with later versions of their software, prompting me to repeat the same experiments with the following Browsers/versions:
- Internet Explorer 7.0
- FireFox 1.5
- Netscape 8.1
- Opera 9.01
The results did not show any significant differences, with the exception of Opera. Consequently, the results for both versions were given. Otherwise, the results presented pertain to the most recent versions of the other browsers.
Starting Point
Starting with a simplistic page, with a very minimal basic styling:
| C S S |
body
#test
p |
H T M L |
<body> <div id="test"> <p> This is some text.... </p> </div><!-- test --> </body> |
This sets the body background color to dark green. A test block - #test, with its background set to light yellow, was inserted inside the body.
Now, let's take a look at this simple page we are starting from:
|
IExplorer 7.0 |
Mozilla 1.7 |
FireFox 1.5 |
Netscape 8.1 |
Opera 7.54 |
Opera 9.01 |
No surprises.. What we see, is what we expected! #test (and its contents) is on a yellow background, inside a dark green body, which occupies the entire screen. End of subject; right? No, Not that simple. This is just only the beginning.
html - The Chameleon
Well, at this point let me introduce our secret weapon, by assigning a background color - dark red, to the html element:
| CSS |
html {background: none #a52a2a;} |
|
IExplorer 7.0 |
Mozilla 1.7 |
FireFox 1.5 |
Netscape 8.1 |
Opera 7.54 |
Opera 9.01 |
The screen is now mainly dark red - background color assigned to the html element, with some or no green - background color assigned to the body element. In other words, the body element shrank as dictated by its contents, subject to the differences of rendition for each browser.
Observations:
- The html element masquerades as the body element, when the former is left in its natural state (i.e. default).
- This, in turn clearly shows that, what most may of think of "the space below the p element" as being part of the body element, while it is actually part of the html element.
- Another important implication is the fact that, without this separation, all phenomena observed in relation this, and, possibly other CSS properties of the body element, would be interpreted as to be "within the realm of the body element", thus resulting in possible misconceptions and false interpretations.
- But, again.. Let's face it: Who, in his/her right mind, would start a web page by assigning a background color to the html element?
Comparing Notes....
The html element masquerading as the body element, appears to be with total blessing of W3C per CSS 2.1:
For HTML documents, however, we recommend that authors specify the background for the BODY element rather than the HTML element. For HTML documents whose root HTML element has computed values of 'transparent' for 'background-color' and 'none' for 'background-image', user agents must instead use the computed value of those properties from that HTML element's first BODY element child when painting backgrounds for the canvas, and must not paint a background for that BODY element. This does not apply to XHTML documents."
« Reference: CSS 2.1 - 14.2 The background »
« Referenced Date: January 22, 2006 »
http://www.w3.org/TR/CSS21/colors.html
Height & Width
While we are here, let's see if the wide spread assumption of setting the height and width of the body element to 100% is a "cure-all":
| 1DD13S |
html {background: none #a52a2a;}
|
|
IExplorer 7.0 |
Mozilla 1.7 |
FireFox 1.5 |
Netscape 8.1 |
Opera 7.54 |
Opera 9.01 |
Observations:
- While this may seems to work (with some irregularities in some cases) for all browsers in Quirks Mode, but obvoiusly not in the Standards Mode.
- In the Standards Mode (with the exception of Internet Explorer), it appears that, setting the height and width of the body element to 100% is not sufficient.
Putting the other irregularities observed aside for a moment or two, and let's do the obvious: Set the height and width of the html element to 100% also.
| 1DD14S |
html {background: none #a52a2a; height: 100%; width: 100%;}
|
|
IExplorer 7.0 |
Mozilla 1.7 |
FireFox 1.5 |
Netscape 8.1 |
Opera 7.54 |
Opera 9.01 |
Observations:
- It becomes rather obvious that, in the Standards Mode the height and width of the body element - when specified in proportional units (%) relative to the Screen (aka Peep-Hole), is a function of the height and width of the html element.
- Internet Explorer appears to be the only exception noted. On the other hand, specifying the height and width of the html element had no effect what-so-ever on the rendation in Internet Explorer.
Margin & Padding
Now, let's step back to analyze the "irregularities" observed:
- With the exception of Opera, these irregularities mainly consist of the ribbons of html element, around the body element - as indicated by the background colors.
- These ribbons are visible on the left and top of the body element for Mozilla/Firefox and Netscape, and on all four sides for Internet Explorer.
- In all browsers, the vertical and horizontal scrollbars are also activated.
At this point, It becomes obvious, does it not? Yes! Built-in (default) margins and/or padding! Let's prove it, by starting with the margins:
| 1DD15S |
html {background: none #a52a2a; height: 100%; width: 100%;}
|
|
IExplorer 7.0 |
Mozilla 1.7 |
FireFox 1.5 |
Netscape 8.1 |
Opera 7.54 |
Opera 9.01 |
Observations:
- However, this had no effect on Opera 7.54!
- The ribbons disappeared; and, so did the Vertical and Horizontal Scrollbars (Of course, with the exception of the infamous ever-present vertical scrollbar of IE).
- The Vertical and Horizontal Scroll bars were activated due to the margins, which made the actual height and width of the body somewhat greater than 100%. With the margins removed, The body element returned to its specified height and width: 100%!
Now, let's reset the padding property of the body element also:
| 1DD16S |
html {background: none #a52a2a; height: 100%; width: 100%;}
|
||||
|
IExplorer 7.0 |
Mozilla 1.7 |
FireFox 1.5 |
Netscape 8.1 |
Opera 7.54 |
Opera 9.01 |
Observations:
- The left and top "ribbons" disappeared, but not the Vertical Scrollbar.
-
However, we are also observing a new phenomenon in Opera 7.54:
The band below the limits of the body, which causes the activation of the Vertical Scrollbar.
Consequently, we have also formally identified and documented a fundamental "peculiarity" of Opera 7.54 in a very objective and scientific manner. The reason I am saying this is due to the fact that, I have encountered this phenomena on and off, under different circumstances. However, the test files used for this set of experiments clearly identify this phenomenon, in its most essential and "naked" form. For the sake of facilitating references and avoiding possible confusion in nomenclosure, I have termed this "peculiarity" the Bottom Band Syndrome.
Furthermore, it also becomes very obvious that the discovery and clear identification of this phenomenon is solely due to the use of background color for the html element which is different than that of the body element. Should we remove the background specification, this Bottom Band would appear to be part of the body element:
![]() |
Bottom Line
We have identified some fundamental secrets of the body element, and found some-what of a common denominator:
| CSS |
html {height: 100%; width: 100%;} body {height: 100%; width: 100%; margin: 0; padding: 0;} |
Please Note That....
- If proportional setting (i.e. 100%) for the height and width properties of the body element are desired, then the height and width of the element element should also be set to 100%. This applies to all Browsers tested in the Standards Mode, with the exception of Internet Explorer.
- Very obviusly, specifying the background for the html element, when the height and width of the body element are set to 100% with the margins also set to 0, has no real value.
- The padding and/or margin property of the body element may be set to any value other than 0. However, caution and/or further thought is advised!
Lessons Learned...
However, let's not get distracted from a very valuable lesson learned:
The assumption that the browsers will honor the expected - and/or specified by W3C, default values for any given CSS property of any given element, is a boomerang, and a very dangerous one. The default margin/padding setting discussed above is very good example of this. This is true for others too: Top margin of p element, top and bottom margins of the form element, just to mention a few...
So, back to Z Rules: When in doubt, spell it out!
What is Next?
Mission accomplished. We have identified some Browser given privileges of the body element and succeesfully Normalized them, by stripping off these secret privileges. Well, almost.....
However, the Bottom Band Syndrome still lurkes in the shadows. Well..Let's address it.
At this point, first reaction would be to jump to the conclusion that this band belongs to the html element, as indicated by its background color. However, this would be jumping the gun! The experiments conducted exploring the behavior of the Default Browser Scrollbars as a function of the overflow property of the body and html elements, as presented in Scrollin' Along..., clearly demonstrates that the Bottom Band is actually outside the html element and it is a part of the Phantom of Opera. This subject is discussed futher in the study titled Phantom of Opera.
This ended up as a rather short article, compared to the frustrations these UBO's have caused, till they were isolated and identified. Simply by using background colors, we have been able to provide a considerable insight as to the Browser given powers and privileges of the body element, as well as somehow managing to shatter some wide spread assumptions and/or beliefs.
Well, this is just the tip of the iceberg - as you may well guess. Using basicly the same strategies and techniquies, let's move up the hierarchy one more step and and begin our investigation of the html element in Root Alchemy.
- Feed-back & Comments:
- Please send any comments, opinions, and even contributions on this subject, using the Feed-Back Form.
- Further Reading:
- You can review the list of Related Articles, with brief descriptions and links on the Auxiliary Panel,









