Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS line-height Property

Posted in CSS Tutorial
Updated on Oct 03, 2024
By Mari Selvan
👁️ 20 - Views
⏳ 4 mins
💬 1 Comment
CSS line-height Property

Photo Credit to CodeToFun

🙋 Introduction

The line-height property in CSS is used to control the amount of space between lines of text within an element.

It plays a crucial role in enhancing the readability and visual appeal of text by managing the vertical spacing.

This property can be used with various units and values to achieve different spacing effects.

💡 Syntax

The syntax for the line-height property is as follows:

Syntax
Copied
Copy To Clipboard
element {
  line-height: value;
}

Here, value can be a number, a length, a percentage, or the keyword normal.

🎛️ Default Value

The default value of the line-height property is normal, which is determined by the browser and typically around 1.2 times the font size. This value may vary based on the font and the browser's default settings.

🏠 Property Values

ValueDescription
numberA unitless value that is multiplied by the element's font size to calculate the line height. For example, a value of 1.5 means 1.5 times the font size.
lengthA specific length value, such as px, em, rem, etc. For example, 20px sets the line height to 20 pixels.
percentageA percentage of the element's font size. For example, 150% sets the line height to 150% of the font size.
normalThe default value, which depends on the browser's user agent settings.

📄 Example

In this example, we'll set the line height of a paragraph to 1.6 times the font size.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS line-height Example</title>
  <style>
    p {
      line-height: 1.6;
    }
  </style>
</head>
<body>
  <h1>Paragraph with Custom Line Height</h1>
  <p>
    This is an example of a paragraph with a line height of 1.6 times the font size. Adjusting the line height can make the text more readable and improve the overall design of your web page.
  </p>
</body>
</html>

🖥️ Browser Compatibility

The line-height property is widely supported across all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. It is a fundamental property in CSS and should work consistently regardless of the browser.

🎉 Conclusion

The line-height property is a simple yet powerful tool for controlling the spacing between lines of text in your web design.

By adjusting the line height, you can improve the readability of your content and create a more aesthetically pleasing layout. Experiment with different values to find the perfect balance for your design.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy