Open In App

CSS line-height Property

The line-height property in CSS is a crucial feature for managing the space used for lines, particularly in text. It’s important to note that negative values are not permitted, ensuring a consistent reading experience.

Syntax:

line-height: normal|number|length|percentage|initial|inherit;

Property values:

Example: In this example, we are using the line-height: normal; property.

<!DOCTYPE html>
<html>
  
<head>
    <title>CSS line-height Property</title>
    <style>
        .geek {
            line-height: normal;
            background: green;
            color: white;
        }
    </style>
</head>

<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>

    <h2>
        CSS line-height Property
    </h2>

    <div class="geek">
        A computer science portal for geeks.<br>
        This div has line-height: normal;
    </div>
</body>
  
</html>

Output: lineheight

Example: In this example, we use the line-height: number; property.

<!DOCTYPE html>
<html>
  
<head>
    <title>CSS line-height Property</title>
    <style>
        .geek {
            line-height: 2.5;
            background: green;
            color: white;
        }
    </style>
</head>

<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>

    <h2>
        CSS line-height Property
    </h2>

    <div class="geek">
        A computer science portal for geeks.<br>
        This div has line-height: 2.5;
    </div>
</body>
  
</html>

Output: 

lineheight

Example: In this example, we are using line-height: length property.

<!DOCTYPE html>
<html>
  
<head>
    <title>CSS line-height Property</title>
    <style>
        .geek {
            line-height: 2em;
            background: green;
            color: white;
        }
    </style>
</head>

<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>

    <h2>
        CSS line-height Property
    </h2>

    <div class="geek">
        A computer science portal for geeks.<br>
        This div has line-height: 2em;
    </div>
</body>
  
</html>

Output: lineheight

Example: In this example, we are using line-height: percentage property.

<!DOCTYPE html>
<html>
  
<head>
    <title>CSS line-height Property</title>
    <style>
        .geek {
            line-height: 150%;
            background: green;
            color: white;
        }
    </style>
</head>

<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>

    <h2>
        CSS line-height Property
    </h2>

    <div class="geek">
        A computer science portal for geeks.<br>
        This div has line-height: 150%;
    </div>
</body>
  
</html>

Output: lineheight

Supported Browsers: The browser supported by line-height property are listed below:

Article Tags :