CSS font-size Property

CSS font-size Property

CSS font-size property sets the size of the font.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <head> <style> #point{ font-size: 14px; } #point1{ font-size: large; } #point2{ font-size: 150%; } </style> </head> <body> <h1>CSS font-size Property</h1> <p id="point">font-size of this paragraph is 14px.</p> <p id="point1">font-size of this paragraph is large.</p> <p id="point2">font-size of this paragraph is 150%.</p> </body> </html>

Syntax

Using CSS

element{ font-size: 25px; }

Using Javascript

object.size.fontSize="25px";

Animatable

Yes, font-size property is animatable. CSS Animatable Properties Reference.

Default Value

Default value for CSS font-size property is medium.

Property Value

The following table provides a list of values for CSS font-size property.

ValueExplanation
xx-small
x-small
small
medium
large
x-large
xx-large
Specifies the absolute-size keywords, based on the user's default font size.
large
smaller
Specifies the relative-size keywords. The font will be larger or smaller relative to the parent element's font size.
lengthAllows you to define the size of the font in any CSS length unit.
%Sets the font-size to a percent of the parent element's font size.

Using JavaScript

In the following example, we will demonstrate how to change the CSS font-size property of an element using JavaScript.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <body> <h1>CSS font-size Property</h1> <button onclick="myFunction()">Click Me</button> <script> var x = document.getElementsByTagName("h1")[0]; function myFunction(){ x.style.fontSize = "40px"; } </script> </body> </html>

Reminder

Hi Developers, we almost covered 98.7% of CSS Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in CSS.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Meet the Author