Setting Line Height in CSS

CSSWeb DevelopmentFront End Technology

The height of a line can be defined by the CSS line-height property. It accepts only positive values.

Syntax

The syntax of CSS line-height property is as follows −

Selector {
   line-height: /*value*/
}

Example

The following examples illustrate the CSS line-height property.

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
div * {
   margin: 1.5em;
   box-shadow: -13px -10px 10px 1px crimson;
}
#demo {
   line-height: 60%;
}
p {
   box-shadow: 13px -10px 10px 1px grey;
   line-height: 50px;
}
</style>
</head>
<body>
<h2>Demo Heading</h2>
<div>
<p>This is demo text one.</p>
<div>This is demo text two.</div>
<div id="demo">This is demo text three.</div>
</div>
</body>
</html>

Output

This gives the following output −

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
div * {
   margin: auto;
   padding: 3em;
}
p {
   height: 100px;
   width: 100px;
   border: thin solid;
   border-radius: 50%;
   box-shadow: 0 20px 10px 1px grey;
   line-height: 0.6;
}
</style>
</head>
<body>
<h2>What is C#?</h2>
<div>
<p>C# is a strongly-typed language. Every variable and constant has a type, as does every expression that evaluates to a value.</p>
</div>
</body>
</html>

Output

This gives the following output−

raja
Published on 06-Jan-2020 15:07:33
Advertisements