Master Stylesheet: The Most Useful CSS Technique

One of the most common mistakes I see beginners and intermediates fall victim to when it comes to CSS is not removing the default browser styling. This leads to inconsistencies in the appearance of your design across browsers, and ultimately leaves a lot of designers blaming the browser. It is a misplaced blame, of course. Before you do anything else when coding a website, you should reset the styling.

A lot of designers clear the styling with a global reset, but there’s a problem with doing this. Form buttons and fieldsets are among the few elements that are completely destroyed with the global reset. They lose their native styling that goes beyond the browser. Instead, you should pick-and-choose the elements you want to reset. It also makes it easier to apply your own style to common elements.

Below is a basic master stylesheet, I removed some styling from elements to keep it simple, like colors, but once you give it your own touch, you’ll have a stylesheet that will help with the majority of your CSS nightmares:

  1. /***** Global Settings *****/
  2. html, body {
  3. border:0;
  4. margin:0;
  5. padding:0;
  6. }
  7. body {
  8. font:100%/1.25 Arial, Helvetica, sans-serif;
  9. }
  10. /***** Headings *****/
  11. h1, h2, h3, h4, h5, h6 {
  12. margin:0;
  13. padding:0;
  14. font-weight:normal;
  15. }
  16. h1 {
  17. padding:30px 0 25px 0;
  18. letter-spacing:-1px;
  19. font-size:2em;
  20. }
  21. h2 {
  22. padding:20px 0;
  23. letter-spacing:-1px;
  24. font-size:1.5em;
  25. }
  26. h3 {
  27. font-size:1em;
  28. font-weight:bold;
  29. }
  30. /***** Common Formatting *****/
  31. p, ul, ol {
  32. margin:0;
  33. padding:0 0 1.25em 0;
  34. }
  35. ul, ol {
  36. padding:0 0 1.25em 2.5em;
  37. }
  38. blockquote {
  39. margin:1.25em;
  40. padding:1.25em 1.25em 0 1.25em;
  41. }
  42. small {
  43. font-size:0.85em;
  44. }
  45. img {
  46. border:0;
  47. }
  48. sup {
  49. position:relative;
  50. bottom:0.3em;
  51. vertical-align:baseline;
  52. }
  53. sub {
  54. position:relative;
  55. bottom:-0.2em;
  56. vertical-align:baseline;
  57. }
  58. acronym, abbr {
  59. cursor:help;
  60. letter-spacing:1px;
  61. border-bottom:1px dashed;
  62. }
  63. /***** Links *****/
  64. a,
  65. a:link,
  66. a:visited,
  67. a:hover {
  68. text-decoration:underline;
  69. }
  70. /***** Forms *****/
  71. form {
  72. margin:0;
  73. padding:0;
  74. display:inline;
  75. }
  76. input, select, textarea {
  77. font:1em Arial, Helvetica, sans-serif;
  78. }
  79. textarea {
  80. width:100%;
  81. line-height:1.25;
  82. }
  83. label {
  84. cursor:pointer;
  85. }
  86. /***** Tables *****/
  87. table {
  88. border:0;
  89. margin:0 0 1.25em 0;
  90. padding:0;
  91. }
  92. table tr td {
  93. padding:2px;
  94. }
  95. /***** Wrapper *****/
  96. #wrap {
  97. width:960px;
  98. margin:0 auto;
  99. }
  100. /***** Global Classes *****/
  101. .clear         { clear:both; }
  102. .float-left    { float:left; }
  103. .float-right   { float:right; }
  104. .text-left     { text-align:left; }
  105. .text-right    { text-align:right; }
  106. .text-center   { text-align:center; }
  107. .text-justify  { text-align:justify; }
  108. .bold          { font-weight:bold; }
  109. .italic        { font-style:italic; }
  110. .underline     { border-bottom:1px solid; }
  111. .highlight     { background:#ffc; }
  112. .wrap          { width:960px;margin:0 auto; }
  113. .img-left      { float:left;margin:4px 10px 4px 0; }
  114. .img-right     { float:right;margin:4px 0 4px 10px; }
  115. .nopadding     { padding:0; }
  116. .noindent      { margin-left:0;padding-left:0; }
  117. .nobullet      { list-style:none;list-style-image:none; }

You’ll notice the global classes at the bottom, which cover basic styling, and will remove styling that we intially set. For example, the .nobullet and .noindent work great on an unordered or ordered list. You can add your own classes there that you use a lot.

Hope you all found this useful, click here to view the stylesheet.

Updates & Notes

Added styling for super and subscript.

This stylesheet was never meant to be a global reset, which should be avoided because of how it completely destroys form elements. Once the style is reset on, for example, a button, it cannot be brought back.

The whole point of a master stylesheet is so you don’t have to use the global reset. You should develop your own template, or master, stylesheet as a base for all your projects.

I would also like to add that the above stylesheet takes some typographic rules into consideration, such as the spacing between heading tags, paragraphs, and blockquote elements.

Bookmark:  Del.icio.us · Digg · Furl · Google · Reddit · Technorati · Yahoo!

Subscribe Now

Subscribe to our blog by RSS or by email.

Related Posts

  1. Master Layout: Give Your Stylesheet A Friend
  2. Magento Hosting
  3. The $420 Design Contest
  4. You Are Here: Using PHP To Highlight Navigation
  5. Split-Shared Technical Analysis

Comments (138)

Great article, Kyle~

Thanks for sharing!

Why not use the ‘universal selector’ method:
* {margin:0; border:0; padding:0;}

instead of:

html, body {
border:0;
margin:0;
padding:0;
}

that way, you will not need to remove margin, border or padding from anything else (e.g., not from FORM, TABLE, the H-tags, etc etc, as the ” * ” removes the stated declarations of “border, margin, & padding” from everything.) This saves you some KBs in CSS-file size not having to re-state to “zero” for other elements.

Also, this:

body {
font:100%/1.25 arial, helvetica, sans-serif;
}

-Should that ” /1.25 arial, etc ” have some sort of value, in px, em, ex, in, pt, mi, km, ly, -etc?? How is a browser to know if you meant to state “pixels”, “em”, “ex”, “inches”, “points”, “miles”, “kilometers” or “lightyears”? (being blatantly obvious here, -point taken? I assume that a browser would default to show “pixels” if not so stated, but this would fail validation in it’s absence I think ) :-D
Sizing fonts to “100%” and immediately re-sizing to the desired font-size is highly effective for cross-browser font-size disparity issues, but the font-size should be implicitly defined by a value and a unit of measure. :-)
Nice article.
-Joel

@Joel: “Why not use the ‘universal selector’ method”

Well, I mentioned in the article that a global reset, which uses the universal selector, is a bad idea because it completely destroys certain elements that are native to the operating system, and cannot be brought back with CSS.

For example, setup a test page and use the global reset, and then create a form button. Look at the styling of that and compare it to a button that hasn’t been globally reset. You lose not only browser styling, but OS styling as well.

That’s ok if you are using custom buttons throughout, and while that’s not a bad thing, it brings up a usability issue as well (not showing a button that people are used to).

There are other elements that are destroyed as well, I would have to actually test them out to come up with a definitive list.

Cameron Adams of The Man in Blue says, “I’m a bit more judicious in my selection of which elements to zero out.”

I suspect because of this very reason. That, and the fact that you are going to have to adjust the styling of these elements anyways, so might as well do it when you need to.

@Joel: “Should that [font size] have some sort of value”

It does actually, it has a percentage amount:

body {
font:100%/1.25 arial, helvetica, sans-serif;
}

I am hoping the percentage sign shows up for you, if it does not, please let me know. That wouldn’t be good at all :)
Thanks for the comments.

Submitted to Tweako ( http://www.tweako.com )

Steve on 23 April 2007 said:

Joel - Where the font-size is 100%/1.25 Arial - it is actually allowed to miss off a unit for the second part. This is because the number acts as a multiplier, effectively making the line-height equal to 1.25x the font-size. I didn’t know this until the other day either…

Alex on 24 April 2007 said:

Just a small thing.

‘Italics’ and to a lesser extent ‘Bold’ are strictly typographical conventions, so they don’t really have any meaning in non-textual media. It’s often recommended that it makes more semantic sense to call that class something like ‘.emphasize’, rather than ‘.italics’

That means:
a) it’s clear what your markup is trying to say.
b) if, at a later date, you wanted to change the way your CSS represented emphasized text (say, in a font variant that is italicized by default), your styling isn’t tied to a classname that wrongly describes what it is.

@Joel: Should that ” /1.25 arial, etc ” have some sort of value?

Ah! I see what you are saying. I misread what you were saying the first time and thought you were talking about the font-size.

Yes, you do not need a unit of measurement after 1.25. You could, for example, have 1.25em and it would be the same thing.

Steve explained why this is so, thanks.

@Alex: […] the way your CSS represented emphasized text (say, in a font variant that is italicized by default), your styling isn’t tied to a classname that wrongly describes what it is.

I can’t think of a font variant that comes nautrally emphasized that isn’t part of the core web fonts, so I’m not seeing your point on that one.

Second, the reasoning behind “bold” and “italics” is for clarity sake. In most word processing units, and for most people who grew up with the obsolete <i> and <bold> tags, that is why the naming convention.

Either way, you are you free to name those as you wish. This is just how I prefer to do it, and “italics” is easier and shorter to write out than “emphasized” and “weighted” or whatever.

You wouldn’t use this in a paragraph though, you should resort to the traditional <em> and <strong> tags, this is more for setting a block element one font style.

david on 24 April 2007 said:

Actually, I think it is more valid to say that you should not use the universal selector because it can affect page rendering performance. Instead of parsing all elements on the page, it targets specific elements, which is optimal.

Although, it is being reworked a little bit, Eric Meyer just had a post about this not too long ago.

The “bold” and “italic” classes are completely pointless. The logical and proper approach would be marking up the elements with <strong> and <em> (or <b> and <i> depending on the doc-type).

(Unless those elements are aimed to supplement other styles and not to be used on their own)

I’d suggest YUI’s reset.css: http://developer.yahoo.com/yui/reset/
Or the eric meyer one suggested above.

Robert on 24 April 2007 said:

Don’t screenreaders needs the <em> and <strong> tags?

I wondered how long that was gonna take when I saw Eric Meyer’s post 5 days ago, guess I know now :-)

Thanks for the comments and suggestions. I’ve never seen Meyer’s reset or the Yahoo! one either. I will look at them shortly though.

One point I’d like to make out, this stylesheet is not a global reset. It is a master stylesheet that happens to reset commonly used items and apply appropriate styling to them after they have been reset. Apples and oranges here.

Meyer’s version, after looking it it, does not add styling, it’s just removing styling. Second, his version is not cross-browser compatible because it uses the psudeo :before and :after.

If it hasn’t been mentioned already, I suggest using em instead of pixels for vertical distances between elements, especially when it comes to h-tags, p, and those related to text. It will scale much better when adjusting the font size.

This is a very good format to follow. Good job

Alex on 25 April 2007 said:

I guess my point is, a screen reader can say something with emphasis (i.e perhaps slightly louder and/or leaving a small pause either side of the phrase), but it can’t say something with italics.

Likewise, almost all languages have some kind of accepted method for emphasizing phrases within text passages, but not all use italics. Japanese, for instance, I think uses a dot before and after the emphasized phrase. Even english typographical conventions change and evolve over the years.

Look, I’m being a bit pedantic, — it’s not going to crash your system — but I guess if you’re going to take the time to inject more meaning into a document, you might as well make that meaning clear and robust.

Cheers.

Alex,

I see what you’re saying, and I would not use the class to put emphasis on text within a paragraph, just as I would not use the bold class that way either. I would use the respective HTML markup.

Either way, the “Global Classes” section is up to your own preferences. Add or remove things from there as you wish :-)

Alex on 25 April 2007 said:

No worries, Kyle. Certainly using <em> etc inside paragraphs is an obvious one. But technically speaking, it probably holds true for paragraph level stuff too. Is a pull-quote inside a book review P class=’italics’ or P class=’quotedtext’? The browser doesn’t care.

Not trying to be argumentative. I’ve been struggling slightly with this stuff for the last few years myself and I just find it coming up more and more at the moment.

Actually, in that case, I would use the <cite> tag and style accordingly :)
And I never took your comments as argumentative, you brought up a very valid point that I did not consider.

Come to think of it, I’ve actually never used the italics class on an element. I have used the bold one on a few occasions, but it’s rare.

Thanks for the comments though, I’ll be revising this stylesheet based on the comments or new methods of doing things (such as the addition of the sup and sub tags).

Yansky on 26 April 2007 said:

In regards to * {margin:0; border:0; padding:0;} stuffing up forms; couldn’t you just do

* {margin:0; border:0; padding:0;}
* form {margin:auto; border:auto; padding:auto;}
* form *{margin:auto; border:auto; padding:auto;}

Yansky,

Nope, that doesn’t bring back the styling either. Once it’s removed with the global reset, it’s destroyed for good. Basically, don’t use the universal selector reset. I don’t know how much simpler to state that.

I think classes like .float-left and .float-right are borderline mixing design and markup.

I’m currently working on a redesign for ronniescotts.co.uk and the previous designer had the genius idea of calling the columns “leftColumn”, “middleColumn” and “rightColumn”. My design required me to reverse the order, so when I put it up the right column will be called leftColumn and so on.

Of course that’s an extreme example. I’m just trying to warn your readers that you should use those global classes with care or you may accidentally defeat the whole purpose of CSS.

Cheers,

Stefan

Drew on 08 May 2007 said:

Question: Why does my browser ask me if I want to display ‘active content’ when I load this stylesheet into an html file?

What makes this ‘active content’? Sorry I’m a noob. Please let me know or email me drewsecret at gmail dot com thanks!

Kyle on 08 May 2007 said:

Drew,

My only guess would be you are trying to view the file locally in Internet Explorer? Other than that, I have no idea why it would do that, I’ve tested this code by itself and have never had that come up before (in any browser).

Try it live and see what happens.

Chimi Hoffa on 10 May 2007 said:

I agree wholeheartedly about using XHTML for markup of information and CSS solely for style. When you start putting in your XHTML documents, that’s not describing the data; it’s describing the style.

would more accurately describe the data and let you make an important item whatever you wanted it to look like using CSS without confusion.

Great post. I’ll be adopting your concept.

Chimi Hoffa on 10 May 2007 said:

Sorry, my code went away in that last post.

does not describe the DATA, it describes the style.

describes the data and you can style that as you like.

Chimi Hoffa on 10 May 2007 said:

That didn’t work either. Forget it.

stephen on 10 May 2007 said:

i don’t understand why a lot of css developers do things like this

.float-left {float: left;}

isn’t that completely against the point of css? i mean, if i give something

how is that any different than

essentially, a class named “float-left” is just an inline style, unless i’m just missing something. but if we’re supposed to be separating markup from style…and i decide i don’t want my nav boxes to float left anymore…i have to go into the markup and change it, instead of just taking “float:left” out of my .box {} definition.

am i missing something? (very possible)

stephen on 10 May 2007 said:

forgot to add…great article! very informative, very helpful - i do start with a master sheet, but it doesn’t have nearly this much stuff in it. i will definately be adopting some of your techniques - thank you!

stephen on 10 May 2007 said:

whoops, my HTML was taken out…here’s what i had:
—————-
if i give something

{div class=”box float-left”}

how is that any different than

{div class=”box” style=”float:left”}
—————-
sorry for all the posts! i would recommend putting something above the comment box that say “html will be stripped or parsed” :)

I’am a Chinese, please forgive my for my poor English,
I think you some “Global Classes” is not good idea

for example:

<span class=”text-center”> … </span>

same as

<center> … </center>

gr8pixel on 11 May 2007 said:

wow.. thanks for this great article! :-)

David Furber on 12 May 2007 said:

Great discussion!

Is it better to use <strong> and <em> or <span class=”bold”> and <span class=”italic”> etc? Granted that the idea is to separate form from content, one must ask “when is the form part of the content?” When the author of a text says “this is important” that is part of the content. When the designer says “I think the emphasized text ought to be 18px bold green” that’s form. So put the em tag in the html and style it in the css.

When you have a class called “float_left” and all it does is float an element left, are you really removing the style from the structure? You’re embedding the style in the structure in a way that makes the browser refer to the CSS to do what it could have done faster had the “float_left” been inline, without adding any semantic value. What are the chances that you will globally change “float_left” to really “float_right” or not float at all, or have a 5px padding…?

Is em the thing to use for margins and padding? I used to think so. But if you put your font sizes in pixels and use ems for margins, then IE6 users enlarging the font size (which adjusts the em to px ratio) will see the design expanding without any change to the font size.

And the global reset versus targeted resetting in the master stylesheet. I like the approach presented here, in that Kyle only tears down what he means to rebuild, and does so immediately resetting the margins. It’s a more circumspect way of saying “At the beginning of this project I’m going to sit down and decide what I want the colors margins etc of these basic tags to be, before I move on to the layout, individual sections, etc.

David Furber on 15 May 2007 said:

Quoting CodeBit.cn:
[Is] for example:

[the] same as

Yes and no. The “center” tag is not valid XHTML. Your browser will render it, and center the content for you. However, the X/HTML is not the place to tell your content to center itself. That is what CSS is for.

Span class=”text-center” is not much better. It’s equivalent to the “center” tag in that it still puts the style in the HTML, since a class called “text-center” probably won’t do anything other than center the text. It is, however, “valid” XHTML.

Better is to wrap the text to be centered in a semantic tag, such as an “h5″ or “blockquote”. Then you can center the H5 in the CSS w/o needing any spans or center tags. If you use H5 several places but it is centered in only one, look for a parent element that is unique to the H5 that needs to be centered. Let’s say your centered H5 occurs in a form with id of contact_us. Then use
#contact_us h5 {text-align:center;}

If you have these “utility” classes starting out in order to “speed” the development process out of the box, then you still have to go through and clean it up later.

Kyle on 15 May 2007 said:

@Stephen: if i give something <div class=”box float-left”> how is that any different than <div class=”box” style=”float:left”>?

That’s just a personal preference, I personally don’t like using style=”" on an element, unless I’m debugging or coming up with a layout. Why not just store common things like that in classes and use them when necessary?

A good example is the floating of an image to the left, you could just apply the float-left class, or use the preferred image-left class, which adds padding to align the top of the image with the top of the text, because ordinarily it doesn’t line up.

Does it defeat the purpose of CSS? I don’t think so.

Kyle on 15 May 2007 said:

CodeBit.cn,

The reason you wouldn’t use the <center> tag, is because it’s deprecated. It’s the same reason you wouldn’t use the <b> tag, or <br> tag, but instead the <strong> and <br /> respective tags.

Here’s a perfect example of where something like this would come in handy:

See the yellow “highlighted” boxes on the top and bottom of the article? Those are used all over the site, except everywhere else (and perhaps one or two other places) the text is aligned default to the left.

I’m still using <div class=”highlight”> … </div> to bring up the box, but in the case of the social bookmark links, I wanted the text to be centered, so I just apply the class and voila, it’s centered. See the above post for why I just don’t do style=”text-align:center”.

Should I keep this master.css file separate from my other style sheet? Or just continue filling your master.css file up with my styles I make for the site?
How would I call the file(s) then from within the HTML document?

Kyle on 16 May 2007 said:

@Henrik: Should I keep this master.css file separate from my other style sheet [or] just continue filling your master.css file up with my styles I make for the site?

I don’t like using multiple stylesheets, but I know some people that like to split them up into like header.css, navbar.css, footer.css, and so on. Not really the best idea in my opinion. You have more files to call and it’s a hassle to open up multiple files to edit something.

I would keep it all in this file, but call it screen.css since it’s only used for the web. Make sure you keep it organized though, and split up sections with the little comment dividers. Oh, and always keep the global classes at the very bottom of the stylesheet.

So basically, right after #wrapper is where you would place your other styles. I personally like to keep it organized by the flow of the document, so it would follow like so:

#wrapper
#header
#navbar
#breadcrumb
#content
#sidebar
#footer

Just as an example. It makes it easier to remember where things are if you organize your stylesheet in a “visual” sense of how a web page breaks down.

@Henrik: How would I call the file(s) then from within the HTML document?

<link rel="stylesheet" href="/path/to/screen.css" type="text/css" media="screen" />

Kyle,

The example give in my previous post:

<span class="text-center">…</span> and <center>…</center>

Just like David Furber said “it still puts the style in the HTML”, the meaning isn’t suggest use <center instead of <span class="text-center">.

In you current design, the yellow “highlighted” boxes on the top and bottom of the article, the text to be centered, but in next design or other theme, the text should be set to right, then you have to edit the XHTML tag to:

<div class="highlight digg">
    <p class="text-right">...</p>
</div>

my method:

<div class="highlight digg">
    <p>...</p>
</div>
 
.digg p {text-align:center;}

if the text should be set to right, we just edit the css to:

.digg p {text-align:right;}

I can design multiple theme, and no need to change the xhtml.

forgive me for my poor English, do you understand what I meaning ?

john on 18 May 2007 said:

I really think the whole model of article to sly/wanna = be - funny comments is really so ummm…the typical slashdot blunder, the same old boring blog hero wannabe…ummmm web1.5 freakin mess = well 2.0…let’s face it…we are all influenced to acknowledge facebook, ajax, j2ee and sop up whatever css div table replacin cooky ajax freak nut mamma jamma css to freakin bad API to begn with, which will not work out anytime soon - I hate the fact that we can ummmm not adopt a cross platform css slacker estblishment, before sending millionaires to
the moon (where I
prolly won’t be going now I must kill myself in jealousy bad css.

Very nice article, and some great feedback too. A good starting point for any web project.

Spider Dog on 21 May 2007 said:

Have you addressed the issue of whether to use : em versus px ? Any good articles on this you can recommend? thx.

Kyle on 21 May 2007 said:

The issue of pixel versus em is a tricky one. You’ll find people on all sides saying different things, it really comes down to what you are most comfortable with, and how far you want to take things.

I have no problem using pixels for structural elements, like a sidebar, and using ems for font sizes. My sites look the same no matter what browser is being used—aside from the minor differences that all browsers have, which you really can’t nitpick over.

Part of me actually likes how Internet Explorer 6 will not resize an element if it’s in pixels. Why would a user need to resize, for example, your sidebar? The only thing a user would ever want to resize would be the text. At least, that’s what I imagine, correct me if I’m wrong.

It would be nice of future revisions of CSS allowed the author to specifically declare that an element could not be resized, that it had to hold it’s value no matter what.

Then you get into different browsers and how they handle this. Firefox will resize everything, even pixels. And that’s great and all, but as a designer, the main focus right now still lands on Internet Explorer 6.

On the flipside, Opera approaches resizing completely different than other browsers. It treats a web page more like a PDF document, where you’re not simply resizing, but zooming in and out. The layout never breaks because of this.

It’s a wonderful feature of Opera (I’m an Opera user if you couldn’t tell), and I really wish all browsers would come to an agreement on resizing, but I’m not holding my breath.

I have no problem using pixels as a measurement for layout elements. I would not use it for fonts though because of IE6 since it won’t resize it. But keep reading and you’ll see why this shouldn’t matter either.

If you want to set all of your elements with a variable cross-browser unit like em or percentage, then by all means do so. You’re now crossing over into elastic layouts though, much different than fixed or liquid.

Elastic layouts are actually really tricky, because you lose a lot of control, just like you do with liquid layouts, which I strongly advise against. The liquid layout should die, I would rather have a fixed versus elastic debate any day of the week. Yahoo! actually has an elastic layout, and they do an alright job with it.

For a really good example, check out the Elastic Lawn at the Zen Garden.

I personally like to use pixels for layout elements (header, navbar, sidebar, footer, etc.) and ems or percentages for fonts, or things that need to be adjusted.

You’ll notice that in the above stylesheet, textual elements like heading tags, paragraphs, and certain styling of text (like the small tag) use ems for their size, but the spacing (padding) is set in pixels.

Could it be in ems? Sure. Feel free to do that actually. You should develop your own master stylesheet that you’re comfortable with. That’s the whole point of a master stylesheet, to give you a base to start with that you can use on every site you make.

I think designers need to take a different approach though. Why should a user have to resize your website in the first place? Shouldn’t you, as the designer, come up with a font size that pleases everyone? I can guarantee you that no one who comes to this website has had to increase the font size of a page. You can sit back in your chair and read comfortably.

I would take a look at the following article, where they dub this technique as 100E2R, or 100% Easy-2-Read standard. Don’t forget to read Web Design is 95% Typography either.

The first rule they offer makes perfect sense: don’t tell me to adjust the font size! Why should I have to resize my text for one website, and then resize it for another? Why should I ever have to do this? The designer should be the one to come up with a usable layout, column width, font size, and line height, not the other way around.

Sorry this comment is really long and probably all over the place. My thoughts were jumping around and it’s late. I’ll probably have to revise this later, or hell, at least organize my thoughts and write an article about it :)

michael on 22 May 2007 said:

QUOTE: “Why would a user need to resize, for example, your sidebar? The only thing a user would ever want to resize would be the text. At least, that’s what I imagine, correct me if I’m wrong.”

One reason a user would need to resize the text of a sidebar is if they’re having trouble reading it, i.e. eyesight issues. This is also one of the reasons so many people hate IE for resizing: many designers use pixels for their fonts, making sites less user-friendly.

It’s great to have control (one of the awesome things CSS offers us designers) but not at the expense of the user. Remember, you’re not just building for yourself.

Great article and fantastic resource. Thanks.

Kyle on 22 May 2007 said:

Michael,

Ah, but I was talking about the actual sidebar, not the text in the sidebar. I understand why people need to resize text on a site, but “structural” elements like the sidebar and footer do not need to be resized.

That’s what I meant when someone asked if those kinds of elements should be used in ems instead of pixels, or why CSS should allow the author the ability to “anchor” the dimensions of elements if they want.

That brought me to the main point though: why should you have to resize text in the first place? Shouldn’t the designer be the one to set the font size to a reasonable amount?

Font sizes definitely have gone through trends. I remember when small was “big,” and everyone wanted like 8-10 pixels for text (and people still do this with Flash, but you can’t resize text in Flash).

Now we’re realizing that there’s nothing wrong with a big font size, the 100E2R Standard.

Jeff on 24 May 2007 said:

This was a terrific article, but some of your subsequent comments trouble me, Kyle.

“I think designers need to take a different approach though. Why should a user have to resize your website in the first place? Shouldn’t you, as the designer, come up with a font size that pleases everyone?”

As you say, if all user agents did as Opera does, we wouldn’t. Yet we can’t force everyone to use Opera, although I agree it has many great features. So here you come close to suggesting that we design based on the belief that all people use the same screen resolution, or that all see equally well, or simply that you — the designer — know better than I know what I want and need.

“I can guarantee you that no one who comes to this website has had to increase the font size of a page.”

No, I’m afraid you can’t guarantee that. But you can say it, and we can choose to believe it or not. I had GREAT eyesight until I was 48 years old. Now it’s just fair. And for many people with serious visual impairments, 18-point type is a reasonable MINIMUM size.

Some eternal principles of good design do not adapt well to web design, although many do. The difficulty lies both in our ability to conceive of possibilities that we have not experienced (text-only browsers, screen readers, PDAs and cellphone browsers … ) and our ability to manage a fixed set of variables as we let the end user manage the rest. Most of us still haven’t defined exactly WHICH fixed set of variables is OK to control, and which control rightly belongs to the end user. You aren’t alone in this. It’s a struggle, and I think it will be resolved in a few years if we just keep working it and talking about it.

I think the question of font size is pretty well resolved though (and that’s one reason the FONT tag is deprecated). Just because we can’t foresee a reason to increase font size or reduce the size of the viewport, doesn’t mean we should design in such a way that we prevent either one. The user is king, and that is a frightening revolutionary concept for designers. We’d better get used to it so we can get on with it.

Thanks as always for your thought-provoking insights!

jay mcdonald on 25 May 2007 said:

Nice article. Two questions:

1) I tried your recommendation to do the global reset and create a form. It didn’t flatten out the button like you showed, unless I did the border: 0;. What is it that exaclty breaks if i just do the global on margin & padding?

2) “Sizing fonts to ‘100%’ and immediately re-sizing to the desired font-size is highly effective for cross-browser font-size disparity issues, but the font-size should be implicitly defined by a value and a unit of measure.”

I am not familiar with this gimmick. As per Zeldman’s recommendations, I always use px on fonts. I understand the potential benefits of ems, but always steered clear because of the issues with doffering base sizes. Does this trick fix that somehow?

jay mcdonald on 25 May 2007 said:

Additionally, since (as you noted) this is not just a reset like Meyer’s sheet, but also establishes a proactive baseline of styles, I would contribute this handly little chunk for making hierarchical outlines, This falls somewhere in the realm of the last section of your sheet where you go beyond just styling standard elements.

/* other helpful classes */
ol.outline li {
  margin: 0px;
  padding-top: 5px;
  padding-bottom: 0px;
}
ol.outline ol {
  list-style-type: upper-alpha;
  margin-left: 0px;
  padding-left: 20px;
}
ol.outline ol ol {
  list-style-type: decimal;
  margin-left: 0px;
  padding-left: 20px;
}
ol.outline ol ol ol {
  list-style-type: lower-alpha;
  margin-left: 0px;
  padding-left: 20px;
}
ol.outline ol ol ol ol {
  list-style-type: lower-roman;
  margin-left: 0px;
  padding-left: 20px;
}

Great idea. It is much better than a global reset. Thnx.

Kyle,

Great article! Will be integrating this into my styles as well. Can you show the appropriate XHTML doc type that would go with this master style sheet?

You mentioned core fonts in a previous responce. Do you know where I can find a list of those core fonts?

Thanks again for a great article.

XHTML 1.1 Transitional is a good DTD to use, I see no reason for going Strict.

And here’s a list of the core web fonts:

http://en.wikipedia.org/wiki/Core_fonts_for_the_Web

You could obviously add the Lucida and a few other families in there. Safe web fonts would also be good to look at:

http://web.mit.edu/jmorzins/www/fonts.html

Joefrey on 05 July 2007 said:

Nice article.

sunil on 24 July 2007 said:

great one. thanks..

Hello Folks,
Great article - thanks - already bookmarked for several gems of advice.

Kyle said… You’ll notice that in the above stylesheet, textual elements like heading tags, paragraphs, and certain styling of text (like the small tag) use ems for their size, but the spacing (padding) is set in pixels.

I wholeheartedly support this because in my experience this gives you the best cross-browser reliability for a fixed layout.

As for your 100% assertion on not resizing - you may live to regret that claim. If ever you visit someone with poor eye-sight and just glance at their computer, you’ll get a shock! Watch them use it and the effect gets even more profound. It taught me a very valuable lesson, especially as my site _is_ aimed at people of “a certain age”.

From the feedback I get, the fact that I provide instant and remembered re-sizing for non-computer-savvy folks is much appreciated. When I ‘phoned a mate to ask him to test it for me, just the expression of his “Ah, that’s much bettter!” said it all.

Providing the 4 options as I do offers speed-reading for the occasional and able visitor as the default, 2 enlarging options based upon screen size and another as basic text for screen-reading technology.

Looking at my logs, I’m amazed that Opera is still so low in the %age charts - as a guy with disabled hands it’s my browser of choice, though I also use Firefox. IE resides here _only_ for testing purposes.

Regards,
Steve (Peter S.)
Caronia II Timeline Webmaster

Great articles dude, i have saved it to my favorites.

You know the button thing you mention has nothing to do with resetting margins and paddings. You can still use the * greedy star to do that without the effect you mention.

Another thing: sure it’s always best to address the HTML tags that is actually used on the site. But the whole idea with master style sheets is to make a style sheet that can be used in any project. And some projects might involve HTML code that you can’t control, from different CMS applications or simply manual HTML from the client.

A very interesting article, and also some very interesting comments too!

Reading in to what Alex said about the 100%/1.25 Arial stuff, I’m believe he has a point about putting a unit of measurement at the end of it, it’s better to use common practice and always specify units of measurement whether you have to or not (whether it validates or not) it might be anal to do it, but if people get into the habit of remembering to specify, then they are less likely to forget in other times.

A quick helpful hint too: Always reset your font sizes in the body element to 62.5%, this sets and standardizes your page fonts to 10px, and alows for very very easy use of decimal measurement with em. As it is best practice to use em’s for everything, I advise that this is always done. I used to have nightmares about developing the CSS for my clients sites until I adopted this method, then the sun came out and made it sooo much easier to measure things.

I’m going to be integrating your master style sheet into our framework that we are currently working on….

You have hit the nail by discussing about CSS Stylesheet because most newbies and sometimes even experienced webmasters face the problem of browser compatibility.

Good info. Thanks for sharing.

Paul on 04 January 2008 said:

Interesting article! I think you present a lot of good information, though it seems like a number of the style declarations could be consolidated.

I do have to disagree with your “global classes” section, however. ‘Class’ attributes should be defined to describe the content, not the formatting. It would be better to classify a block of text as ’subsection_title’ then apply font and spacing formatting. This gives the designer more flexibility in coming back to a semantically correct page of markup to apply different styles as needed, without having to change class attributes as formatting changes. Otherwise, using class attributes that reflect formatting is no different from defining an inline style or a FONT element.

Eric on 18 January 2008 said:

Some good CSS, thanks for posting. However, you lose credibility when your own website doesn’t render well in Firefox. The numbered listed is mucked up…

Thanks as always for your thought-provoking insights!

Great article, i love css
Profesional web hostin service http://www.totoidc.com

HI i need your help i really want to create my own website/web page but i dont know how to go about doing it so can you please help me out

Nice article…..

nice

Однако… А чо это за сцылки?

Trackbacks & Pingbacks

  1. 101 CSS Resources to Add to Your Toolbelt of Awesomeness
  2. Drainedge Link Tank · Today’s Links
  3. Steve Miller’s Web Sites of Interest » links for 2007-04-25
  4. links for 2007-04-25 — minizen — diseño web
  5. The WP Themes » Blog Archive » Master Stylesheet: The Most Useful CSS Technique
  6. Nutspress : Blog Archive : 使えるCSS活用術-パラグライダー・CMS実験道場・アフィリエイトブログ
  7. links for 2007-04-25 « toonz
  8. Recommended Reading for 24th April through 25th April
  9. Fatih Hayrioğlu’nun not defteri » 28 Nisan 2007 Web’den seçme haberler
  10. Stumbling Findings 5/6/2007
  11. 70 Expert Ideas For Better CSS Coding | Smashing Magazine
  12. Webdesign (css, grafica e altro) » Blog Archive » 70 Expert Ideas For Better CSS Coding
  13. Did you Know? » Blog Archive » 70 Expert Ideas For Better CSS Coding
  14. Web-Design Blog » Blog Archive » 70 Expert Ideas For Better CSS Coding
  15. holotone.net
  16. Best of April 2007 | Smashing Magazine
  17. Webdesign (css, grafica e altro) » Blog Archive » Best of April 2007
  18. » 25 Code Snippets for Web Designers (Part5)
  19. The Way The Internet Should Be! » Blog Archive » 25 Code Snippets for Web Designers (Part5)
  20. roScripts - Webmaster resources and websites
  21. Apresentando: Cadulicious - Cadu de Castro Alves
  22. links for 2007-05-18 | klick wech | XSBlog2.0beta
  23. Thoughts on Design » Master CSS
  24. Goodies! | Flawless Mind
  25. Medina » Blog Archive » Sorry. Blogger is down.
  26. Tekjuice.com » Blog Archive » Best of April 2007
  27. Daily Links for 05/29/2007 | Xpansion 2.0 : Blog Archive : Daily Links for 05/29/2007
  28. 25 Code Snippets for Web Designers (Part5) | streaminterviews.com
  29. the designer’s pages » Blog Archive » Expert Ideas For Better CSS Coding
  30. Donnybrookdesign.com :: The Web Design Card Catalog (Part I: CSS, HTML, Javascript & PHP)
  31. NATE TODD | Designer » Developer » CSS Reset
  32. 25 Code Snippets for Web Designers (Part5) | Photoshop Tutorials
  33. 25 Code Snippets for Web Designers (Part5) | Quentin Brown
  34. Aritz Oiaga Blog » Blog Archive » Hoja de estilos maestra
  35. Réinitialisation des éléments HTML
  36. Open Source Web Design » Blog Archive » 70 Expert Ideas For Better CSS Coding
  37. De nouveaux sites pour améliorer et optimiser les CSS
  38. webiga.com » Jump start CSS
  39. dot… » 70 Expert Ideas For Better CSS Coding
  40. Master Stylesheet The Most Useful CSS Technique
  41. 47 CSS Tutorials, Techniques, and Resources » Webmaster-Source
  42. Web Design Resource List v3.0 |
  43. CSS Specificity: Things You Should Know at Undocontrol
  44. CSS Frameworks + CSS Reset: Design From Scratch | CSS
  45. lost node » Blog Archive » CSS Frameworks + CSS Reset: Design From Scratch
  46. CSS Frameworks + CSS Reset: Design From Scratch .
  47. css, php, dhtml и java статьи и скрипты » 70 способов улучшить CSS код
  48. Obez Blog » CSS Frameworks + CSS Reset: Design From Scratch
  49. 70位专家谈CSS设计 | 一个全新的 WordPress Blog | PureCSS
  50. » CSS Frameworks + CSS Reset: Design From Scratch
  51. Budget Web Hosts » Crucial Web Hosting " Blog " Master Stylesheet: The Most Useful CSS Technique
  52. CSS Selectors: Use Classes « Ian Lotinsky
  53. Budget Web Hosts » Crucial Web Hosting " Blog " Master Stylesheet: The Most Useful CSS Technique - Bon Echo
  54. Trajcek » CSS Frameworks vs. CSS From Scratch
  55. Css - 101 recursos impresionantes del CSS
  56. 101 awesome CSS Resources - Graphic Design Forum and Web Design Forum
  57. 101 recursos CSS
  58. PlayCSS » 70位专家谈CSS设计
  59. Thoughts from a Black Hole » Blog Archive » Master Stylesheet: The Most Useful CSS Technique
  60. 70位专家谈CSS设计 | 晨风·社
  61. CSS Frameworks + CSS Reset: Design From Scratch » » Google Adsense News
  62. CSS Concept » Blog Archive » CSS Coding in Experts opinions..
  63. – Code Hound – » Blog Archive » Master Find: Master Style Sheets
  64. 125 Code Snippets for web designers | PaulSpoerry.com
  65. *С изюминкой » 70 советов по написанию продвинутого CSS-кода
  66. » Frameworks CSS + Reset CSS : design from scratch « css4design : des css pour votre design html
  67. Best practices and advices | Ionut Staicu - Webdeveloper Blog
  68. egyptianwebdesigner.com » Blog Archive » 70 Expert Ideas For Better CSS Coding
  69. What is global CSS reset? | HTML-Advisor
  70. 70 Expert Ideas For Better CSS Coding | Cổng thông tin hty.net

Leave A Reply

Helpful Hint

To post HTML or other code, wrap your text in the <code> tag.