What is the default font for elements in html if font is not set in css

I want to know what is the default font for elements in an html document.
for example if i use this jquery code:
var elemfont = jQuery('.elem').css('font-family');


What does it return if font is not defined in css?
And what is returned if the parent has a font?

+3


source to share


2 answers


Most browsers have this serif

as default font-family

if not specified. serif

allows Times or Times New Roman, depending on your operating system, etc.



If you call $(document.body).css("font-family")

where the font is not set in the body or parent, jQuery won't give you serif

, but it allows the browser's default font name and gives you that. On Windows, Chrome, FF or IE, you get "Times New Roman"

.

+1


source


The default font depends on the browser and the element. Most browsers have a default font that they apply to the element body

and it is inherited by the inner elements when nothing else interferes, but browsers also have special standard fonts installed, for example for elements input

and select

. Moreover, if an element contains characters that are not in the browser's default font, the browser is expected to scan the fonts on the system to find the one that received it.



What it returns jQuery('.elem').css('font-family')

is really a different question and should be asked separately and flagged as a jquery question. However, the answer is quite simple: according to the jQuery documentation , it .css(font-family)

returns the computed value 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 an element will appear in this font only for the browser to check that font first when looking for fonts for characters.

+3


source







All Articles