Font Sizes in CSS

font-size property?

  • The font-size property sets the size of a font.


This will be our boilerplate:

index.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title> Font Sizes in CSS </title>
    <style>

    </style>

</head>
<body>

</body>
</html>


Font Size Property values

i) px: The px value is normatively defined as being exactly 1/96th of an inch.

.p {
    font-size: 20px;
 }


ii) em:  Relative to the font size of the element (2em means 2 times the size of the current font).

.p {
    font-size: 2em;
 }


iii) rem: This property value is relative to the font size of the root element.

.p {
    font-size: 4rem;
 }


Using Font Size Properties

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=s, initial-scale=1.0">
    <title>font-size in css</title>
    <style>
        .px-size {
            font-size: 20px;
        }

        .em-size {
            font-size: 2em;
        }

        .rem-size {
            font-size: 4rem;
        }
    </style>
</head>
<body>

    <p class="px-size"> This is first paragraph </p>
    <p class="em-size"> This is second paragraph </p>
    <p class="rem-size"> This is third paragraph </p>

</body>
</html>

Output:


CSS Font Sizes Property PDF

Download Now

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Top Post Ad

Below Post Ad