Reputation: 96
I want know what is the default font for elements in a html document.
for example if i use this jquery code :
var elemfont = jQuery('.elem').css('font-family');
What it returns if there is no font defined in css ?
And what returns if its parent has a font ?
Upvotes: 3
Views: 2946
Reputation: 201588
The default font depends on the browser and on the element. Most browsers have a default font that they apply to the body
element, and it gets inherited by inner elements when nothing intervenes, but browsers also have special default fonts set e.g. for input
and select
elements. Moreover, if an element contains characters that are not present in the browser’s default font, the browser is expected to scan through fonts in the system to find one that has got it.
What jQuery('.elem').css('font-family')
returns is really a different question, and should have been asked separately and tagged as a jquery question. However, the answer is rather simple: according to jQuery documentation, .css(font-family)
returns the computed value of font-family
for the first element in the set of matched elements. In the absence of any CSS settings, this will be the specific font family used as the browser’s default font. As mentioned above, this does not guarantee that all (or any!) characters in the element will be displayed in that font—only that the browser will first check that font when finding fonts for characters.
Upvotes: 3
Reputation: 3769
Most browsers have serif
as the default font-family
when one is not specified. serif
resolves to Times or Times New Roman, depending on your operating system, etc.
If you call $(document.body).css("font-family")
where a font is not set on the body or a parent element, jQuery will not give you serif
, but resolve the browser's default font name and give you that. On Windows, on Chrome, FF, or IE, you'd get "Times New Roman"
.
Upvotes: 1