Ways to set Font size with CSS and HTML font tag

Font size in HTML

The font size attribute sets the size of text in the headings, div, paragraphs, links etc. You can specify the size in the font tag of HTML or by using the CSS.

You should avoid using the font tag for future developments as this is not supported in HTML 5. Instead of that, you should use CSS properties to set the size of text on your web pages.

Following are examples to set the font size by using both ways.

Example of HTML font size by font attribute

The following example shows how to set the font size in the <font> tag of HTML. The example sets the font for h1 and h2 headings along with a paragraph.

Font size with CSS example

The following example sets the font by using the font-size property inside the CSS block. We used <h1>, <h2> and <div> tags of HTML where font is applied. The <p> tag size is in em while <h1>’s size in pixels and <h2> size is set with the points.

You can see, we have defined the font size properties in the CSS block, under the head section of the document.

You can also create external CSS files and create classes or IDs to apply the font size and other font properties to different elements of the document.

Was this article helpful?

Related Articles

Leave A Comment?