Difference Between height and line-height Properties in CSS

The height and line-height are two different properties in CSS. They both are used to serve two different purposes on a web page.

The height property is used to set the height of a container such as a div element. OR, In simple words, the height property is used when want to set the size of an HTML element.

The line-height property on the other hand has nothing to do with the element’s size. It is rather used to set the vertical spacing between two adjacent lines of text.

The higher the value of the line-height, the more will be the vertical spacing between the adjacent lines of text.

See this image:

And here is a working example which shows the difference between the two:

Example:

div{
   height: 200px;
   line-height: 50px;
   width: 300px;
   background: springgreen;
   padding: 10px;
}

Author

  • Manoj Kumar

    Hi, My name is Manoj Kumar. I am a full-stack developer with a passion for creating robust and efficient web applications. I have hands-on experience with a diverse set of technologies, including but not limited to HTML, CSS, JavaScript, TypeScript, Angular, Node.js, Express, React, and MongoDB.