The body Tag

The <body> Tag

I've already mentioned that you can adjust the margin, padding, and border of a page by applying styles to the <body> tag. More importantly, any styles that you want to apply on a pagewide basis can be assigned to the page's body. You already know about setting the background color for the page by using style="background-color: black" in your <body> tag. That's really just the beginning. If you want the default font for all the text on your page to appear in the Georgia font, you can use the following style:

body { font-family: Georgia; }

That's a lot easier than changing the font-family property for every tag that contains text on your page. A common <body> tag you often see looks something like

<body bgcolor="#000000" text="#ffffff" alink="blue" vlink="yellow" alink="purple">

You can modify the background and text colors like this:

body { color: white;     background-color: black; }

I'll explain how to alter the link colors shortly. One of the main advantages of taking this approach, aside from the fact that it's how the standard says you should do things, is that then you can put the style into a linked style sheet and set the background color for your whole site on one page.

Many layouts require that elements be flush with the edge of the browser. In these cases, you need to set the margin to 0 for your <body> tag. Some browsers enabled you to do this with proprietary attributes of the <body> tag, but they're not reliable. To turn off margins, just use this rule:

body { margin: 0px; }

Sams Teach Yourself Web Publishing with HTML and CSS in One Hour a Day
Sams Teach Yourself Web Publishing with HTML and CSS in One Hour a Day (5th Edition)
ISBN: 0672328860
EAN: 2147483647
Year: 2007
Pages: 305

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: