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 position three divs horizontally

    How can I fit the iframe height at 100%?

    Jquery show/hide more data

    How to make the text that are typed inside the input to appear into a seperate div

    CSS: How to change class style if another style is hover

    How to avoid css and scripting effect when input on textbox

    How to create a list with three columns in a row by css and html?

    How to switch tabs and change css class on click using Angular2?

    How can I target text input fields with CSS?

    How to target a CSS ID to a specific HTML tag [closed]

    JQuery.ready is too late: How do I apply CSS Values with JQuery before Rendering?

    How can you hide CSS from the iPhone, but not other browsers?

    how to check css is valid for IE8

    How to vertically align both image and text side by side in a div

    How to change element CSS class when different part of web page is present?

    How to detect a smartphone through JavaScript/CSS?

    How to localize the CSS just for this table's use?

    How to create a natural-looking line using css and maybe javascript? [closed]

    How to change horizontal block-level elements to vertical elements after specific width?

    How to remove IconTabFilter icons using css?

    How to index star rating in google?

    How do I make this menu using only HTML and CSS

    How to use background css for an image not in the Content or Resource folder

    How to create a header which fills the background with a color throughout the width

    How to put background-color only a section of a select? CSS

    How can I ensure that text is inside rounded div?

    how to make header title with buttons

    How to position the arrow of this widget correctly?

    How to inline style an embedded gist with CSS

    How do I change image on hover of that the img is in - in jQuery?