How font size works in CSS?

This is a discussion on "How font size works in CSS?" within the Web Page Design section. This forum, and the thread "How font size works in CSS? are both part of the Design Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Dec 2nd, 2005, 15:08
New Member
Join Date: Dec 2005
Location: UK
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
How font size works in CSS?

Hi All,

This must be the very simple question for all there.

If I set size for <h1> using

h1 {font-size: 1em}

then try displaying a h1 text. It is displayed as normal text not as default h1 font size of browser? Why as 1em means relative to default of browser?


Thanks in advance for spendinf time on this very simple question.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Dec 2nd, 2005, 22:14
Reputable Member
Join Date: Sep 2005
Location: Canada, BC
Age: 24
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

1em = 100% the size of the parent font
.5em = 50%
1.5em = 150% etc
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Dec 12th, 2005, 20:49
Junior Member
Join Date: Dec 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

Hi,

Just a handy little note but I believe that most browsers have a default size for 1em = 16 pixels (approx).

When using em's you should really set the body font-size to 100%:
eg body {font-family: verdana, ariel, sans-serif; font-size:100%;}

Gecko.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Dec 12th, 2005, 21:23
Reputable Member
Join Date: Sep 2005
Location: Canada, BC
Age: 24
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

That is not how em works at all...
em defines the text size in relation to the font size of the parent element.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Dec 18th, 2006, 18:20
Up'n'Coming Member
Join Date: Jun 2006
Location: Northern Ireland, United Kingdom
Age: 22
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

Quote:
Originally Posted by Pheonix View Post
That is not how em works at all...
em defines the text size in relation to the font size of the parent element.
Correct, and I think the overall em is based on your browsers default font size
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Dec 18th, 2006, 19:47
Reputable Member
Join Date: Jul 2006
Location: Scotland
Age: 22
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

em is based on the width of the capital letter 'M' of the parent font...

so 1em is one 'M', .5em is half that size as pheonix said.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Dec 18th, 2006, 21:11
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

You will find what you need to know about ems if you look in the sticky at the top of the css forum.

Edit: This sticky is entitled, 'CSS query - start here'.

Why does nobody seem to understand this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Dec 18th, 2006, 21:25
Reputable Member
Join Date: Nov 2006
Location: London, England
Age: 15
Posts: 175
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

lol i have done that so many times...... i go to that first now
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Dec 19th, 2006, 01:01
Reputable Member
Join Date: Sep 2005
Location: Canada, BC
Age: 24
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

This thread is a year old o.O I don't understand why its been brought back
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Dec 19th, 2006, 01:17
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

It's a ghost.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Dec 19th, 2006, 04:59
Reputable Member
Join Date: Sep 2005
Location: Canada, BC
Age: 24
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

/calls an exorcist
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Dec 19th, 2006, 10:32
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

Oh no! Not one of them!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Dec 19th, 2006, 10:33
Daniel's Avatar
Elite Veteran
Join Date: Sep 2006
Location: The Kingdom of Rabbits
Age: 21
Posts: 2,051
Blog Entries: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

wooooooooooooooooooooooooooooooooooooooooooooooooo ooooooooooooooooooooooooooooooooooooooooooo
Last Blog Entry: Assassin's Creed (Nov 22nd, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old Dec 19th, 2006, 14:01
Elite Veteran
Join Date: Aug 2005
Location: That Place
Posts: 2,044
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Re: How font size works in CSS?

0.9em is a good general font size with 0.85em or so for large scale fonts such as verdana.
__________________

Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old Dec 19th, 2006, 14:50
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

I've heard a lot of controversy over this, but do you think it's bad to declare font-size: 70%; in the body tag? It makes it way easier to use intergers for paragraphs and headers.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #16  
Old Dec 19th, 2006, 15:01
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

I believe the size you set in the body tag should be the default size for your site.

Coupled with the fact the the end-user has the option in their browser (well in any decent browser) to set both the normal and minimum font size, this default should represent 1em but set as a percentage - see sticky.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #17  
Old Dec 19th, 2006, 15:20
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

Er. I'm confused. When you say "1em but set as a percentage," that should just be 100%... As for the sticky, I don't see anything relevant to what I was trying to say.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #18  
Old Dec 19th, 2006, 15:23
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

I was referring to setting the body font size to 100.01% because of a quirk in IE.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #19  
Old Dec 20th, 2006, 01:30
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

Does using 70% fix the quirks? I'm having a hard time finding detailed information on the bug.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #20  
Old Dec 20th, 2006, 22:56
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

Here is one reference:
http://css-discuss.incutio.com/?page...xplorerWinBugs

Google with '+IE +font +sizing +bug +100%' will get you quite a few more.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
font,