CSS Line Height

The line-height property in CSS is used to control the amount of space between lines of text within an element. It is an essential property for improving text readability and overall design aesthetics, especially when dealing with paragraphs, headings, and multi-line text content.

Key Points on CSS Line Height:

Syntax for CSS Line Height:

Syntax Example

/* Line height syntax */
        line-height: normal | number | length | percentage;
        
        /* Example */
        line-height: 1.5;

Examples of CSS Line Height:

The following examples demonstrate the usage of the line-height property:

Code Example: Line Height Normal


            p {
            line-height: normal;
              }

Output

This paragraph uses the default line height. The lines are spaced according to the browser's default value.

Code Example: Line Height Number


            p {
            line-height: 1.8;
              }

Output

This paragraph has a line height of 1.8. The space between lines is increased for better readability.

Code Example: Line Height Length


            p {
            line-height: 30px;
              }

Output

This paragraph has a line height of 30px. The lines are spaced with a fixed height of 30 pixels.

Code Example: Line Height Percentage


            p {
            line-height: 150%;
              }

Output

This paragraph has a line height of 150%. The lines are spaced at 150% of the font size.

Common Line Height Values:

Common Line Height Use Cases:

The line-height property is crucial for making text more legible and enhancing the overall layout. By adjusting the line height, you can avoid cramped or overly spaced text and achieve better visual balance.