Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to set font-family: body or html element?

Tags:

Where is it best to declare the font-family CSS property? On the html or body element?

html {     font-family: sans-serif; } 

or

body {     font-family: sans-serif; } 

I searched online, but I cant find a definitive answer.

like image 506
Frank Underwood Avatar asked Mar 21 '17 11:03

Frank Underwood


People also ask

Where do you set font size in HTML or body?

To change the font size in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property font-size.

Which attribute of font is used to set the font-family?

In CSS, we use the font-family property to specify the font of a text.

Is font an HTML element?

The <font> HTML element defines the font size, color and face for its content. Warning: Do not use this element. Use the CSS Fonts properties to style text.


1 Answers

Best practice is to set the font-family in the body.

body {    font-family: Arial !important; } 

The !important is useful here so that in case you are using any other framework, your font-family does not get overridden.

You can also use the * selector.

* {     font-family: Arial !important; } 

The *-selector means any/all elements, but will obviously be on the bottom of the property chain when it comes to overriding more specific selectors.

Note that the !important flag will render the font-style for * to be absolute, even if other selectors have been used to set the text (for example, the body or maybe a p).

like image 167
nashcheez Avatar answered Sep 27 '22 17:09

nashcheez