Atrybut CSS line-height

Definition and usage

The line-height property sets the distance between lines (line height).

Note:Negative values are not allowed.

Description

This property affects the layout of the line box. When applied to a block-level element, it defines the minimum distance between the baselines within the element, rather than the maximum distance.

The difference between the calculated value of line-height and font-size (in CSS known as 'line spacing') is divided into two halves, which are added to the top and bottom of each line of text content. The smallest box that can contain these contents is the line box.

The original numeric value specifies a scaling factor, and the descendant elements will inherit this scaling factor instead of the calculated value.

See also:

CSS tutorial:Tekst CSS

HTML DOM reference manual:lineHeight property

Example

Set line height in percentage:

p.small {line-height:90%}
p.big {line-height:200%}

Try it yourself

(More examples can be viewed at the bottom of the page)

CSS syntax

line-height: normal|number|length|initial|inherit;

Attribute value

Value Description
normal Default. Set a reasonable line spacing.
number Set a number, which will be multiplied by the current font size to set the line spacing.
length Set a fixed line spacing.
% Percentage line spacing based on the current font size.
inherit Specifies that the value of the line-height property should be inherited from the parent element.

Technical details

Default value: normal
Inheritance: yes
Version: CSS1
JavaScript syntax: object.style.lineHeight="2"

Przykład TIY

Ustawianie odległości między wierszami za pomocą wartości procentowej
Ten przykład pokazuje, jak użyć wartości procentowej do ustawienia odległości między wierszami w akapicie.
Ustawianie odległości między wierszami za pomocą wartości pikselowej
Ten przykład pokazuje, jak użyć wartości pikselowej do ustawienia odległości między wierszami w akapicie.
Ustawianie odległości między wierszami za pomocą liczby
Ten przykład pokazuje, jak użyć liczby do ustawienia odległości między wierszami w akapicie.

Wspierane przeglądarki

Liczby w tabeli wskazują na pierwszą wersję przeglądarki, która w pełni obsługuje tę właściwość.

Chrome IE / Edge Firefox Safari Opera
1.0 4.0 1.0 1.0 7.0