How to set font family and size in html/css


Tags: html,css

Problem :

I'd like to use css syntax in HTML document to set the font-family to "Arial" and font-size to 0.3cm for the whole document.

I use this code:

<style>
body { font-family: Arial; font-size: 0.3cm }
</style>

I am not sure if writing only Arial is enough, or should I write something like this?

<style>

body { font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; font-size: 0.3cm }
  </style>

and I am also not sure if I cam use "cm" in the code, I mean it works in the browser but is it correct "code-wise" ?

thanks



Solution :

font-family: Arial

This means the browser will use Arial if you have it installed on your system. If not, it will use whatever the default font is for your browser.

font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif

This means the browser will use Arial if you have it installed on your system. If not, it will use Helvetica Neue if you have it installed on your computer. If not, it will use Helvetica if you have it installed on your computer. If not, it will use whatever the default sans-serif font is for your browser.

Both are perfectly valid. They just do slightly different things.

and I am also not sure if I cam use "cm" in the code

Yes, cm is a valid CSS unit of measurement.


    CSS Howto..

    How to create a div in the same size as the contained image. Both should be responsive

    How can I make a fixed background image not stay fixed on scroll?

    How can I add custom search box on page?

    how to make an odd shaped html/css menu?

    How to Reset CSS after Media Query?

    How to avoid an unknown height sticky footer to overlap content with CSS only?

    How to select every 4th div inside another div CSS Selector [closed]

    How to put background after anchor tag throw css?

    How do you work on your HTML and CSS in PLay! + intellij idea? [closed]

    How to invert colors using CSS on hover

    How to set jQuery draggable min/max-left and min/max-right

    how to add a CSS class inside a JavaScript setup code?

    How do I achieve a hover over image effect?

    How to use CSS selectors to retrieve specific links lying in some class using BeautifulSoup?

    How do I change the text inside a button?

    How to merge CSS classes?

    How to center in CSS only after specific HTML element?

    How to change Google Chrome Arabic default font in css?

    How to align content of a div to the bottom?

    “div” into an “a” is wrong. So, how can I do this? (HTML4, CSS2, crossbrowser)

    How to style SVG via css?

    how can i change the css style on click with table

    How to set css style dynamically with angularjs?

    How to make a footer stay on the bottom?

    HTML, CSS - image inside image, how to do that?

    How to add html classes to a Django template 'for-loop' dynamically?

    How to slide/grow a tile to position with 90x90px with CSS

    how to fix customize select box using css?

    IE11 shows every display: table-cell element at a new line

    How to remove last TD in first LINE