lineHeight style property
Specifies or returns the distance between lines of text in a block-level element.
Syntax:
You can find the related objects in the Supported by objects section below.
This property is read/write.
CSS page for this property: line-height |
Possible values:
The type of this property is string.
One of the following values:
A floating point number, the height of the line is the specified number multiplied by the font size of the element. | |||||||
The height of the line in length units. For the supported length units, see the length page. | |||||||
The height of the line is the specified percentage of the font size of the element. | |||||||
Takes the value of this property from the computed style of the parent element. | |||||||
Default. Normal height is used. |
Default: normal.
Example HTML code 1:
This example illustrates the use of the line-height property:
|
||||
<head> <style> .example1 { border: 1px solid blue; font-size: 14px; line-height: 14px; } .example2 { border: 1px solid blue; font-size: 14px; line-height: 20px; } .example3 { border: 1px solid blue; font-size: 14px; line-height: 30px; } </style> </head> <body> <div class="example1"> Sample multiline text <br />with 14px line-height, font-size is 14px </div> <br /> <div class="example2"> Sample multiline text <br />with 20px line-height, font-size is 14px </div> <br /> <div class="example3"> Sample multiline text <br />with 30px line-height, font-size is 14px </div> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example illustrates the use of the line-height property, all of the three div elements have the same line height (24px, 120% of 20px, 1.2 * 20px):
|
||||
<head> <style> .example1 { border: 1px solid blue; font-size: 20px; line-height: 24px; } .example2 { border: 1px solid blue; font-size: 20px; line-height: 120%; } .example3 { border: 1px solid blue; font-size: 20px; line-height: 1.2; } </style> </head> <body> <div class="example1"> Sample multiline text <br />with 24px line-height, font-size is 20px </div> <br /> <div class="example2"> Sample multiline text <br />with 120% line-height, font-size is 20px </div> <br /> <div class="example3"> Sample multiline text <br />with 12px line-height, font-size is 20px </div> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 3:
This example illustrates the use of the lineHeight property in JavaScript:
|
||||
<head> <script type="text/javascript"> function ChangeLineHeight (selectTag) { // Returns the index of the selected option var whichSelected = selectTag.selectedIndex; // Returns the selected options values var height = selectTag.options[whichSelected].text; var anchor = document.getElementById ("myAnchor"); anchor.style.lineHeight = height; } </script> </head> <body> <a id="myAnchor" style="line-height: 1.2em"> Sample multiline text <br />with the specified line-height </a> <br /> <select onchange="ChangeLineHeight (this);" size="10"> <option />0.2 <option />0.5 <option />0.8 <option />1 <option selected="selected" />1.2 <option />1.5 <option />1.8 <option />2.1 <option />2.4 <option />3 </select> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
CSSStyleDeclaration, htmlElement.currentStyle, htmlElement.runtimeStyle, htmlElement.style
HTML elements:
a, abbr, acronym, address, b, basefont, bdo, big, blink, blockquote, body, br, button, caption, center, cite, code, col, colgroup, dd, del, dfn, dir, div, dl, dt, em, fieldset, font, form, h1, h2, h3, h4, h5, h6, html, i, input:button, input:file, input:password, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, label, legend, li, listing, marquee, menu, nobr, ol, p, plaintext, pre, q, rt, ruby, s, samp, select, small, span, strike, strong, sub, sup, table, tbody, td, textarea, tfoot, th, thead, tr, tt, u, ul, var, xmp
Related pages:
External links:
line-height (MSDN)
line-height (Mozilla Developer Center)
line-height (Safari Reference Library)
line-height (W3C)
line-height (Mozilla Developer Center)
line-height (Safari Reference Library)
line-height (W3C)
User Contributed Comments