SlideShare a Scribd company logo
1 of 190
Download to read offline
LINE-HEIGHTINTODEEP DIVE
Why should
you care about
line-height?
Because line-height is an
integral part of CSS-based
layouts.
It can help to make our content
easier to read and
comprehend.
It can be used to control the
vertical rhythm of multiple
column layouts.
It can be used to centre inline
content vertically.
But also because it is one of the
fundamentals of CSS, like font-
sizing, the cascade, inheritance
and selectors.
But before we begin, let's go
back in time and look at the term
ā€œleadingā€.
What is ā€Ø
leading?
Back in the ā€œgood old daysā€ type
was set by hand using printing
presses.
Printed material was created by
setting out letters in rows. Each
letter was created on anā€Ø
individual block.
Leading, or lead strips were
added between the lines of
letters when additional vertical
space was required.
The term ā€œleadingā€ is still used
today in print typography,
where it refers to the distance
between the baselines of
successive lines of type.
In CSS, the line-height property
is used to control the vertical
space between lines.
However, as we will soon see,
ā€œleadingā€ is still used in
association with CSS line-height.
Syntax
The CSS line-height syntax
looks like this:
https://www.w3.org/TR/CSS2/visudet.html#line-height
<'line-height'> = normal | <number> | <length> |
<percentage> | inherit
This means that line-height can
be speciļ¬ed using one of the
following methods:
Option 1: Line-height can be
speciļ¬ed as ā€œnormalā€ which is
the initial value. By default,
browsers use between 1.0 - 1.2
line-height.
body { line-height: normal; }
Option 2: Line-height can be
speciļ¬ed as ā€œinheritā€ which will
inherit the line-height from the
parent.
body { line-height: inherit; }
Option 3: Line-height can be
speciļ¬ed using a percentage
value.
body { line-height: 120%; }
Option 4: Line-height can be
speciļ¬ed using a length value.
body { line-height: 20px; }
A wide range of diļ¬€erent
types of length values can be
used such as:
/* FONT RELATATIVE LENGTHS */
/* font size of the element */
body { line-height: 1em; }
/* x-height of the elementā€™s font */
body { line-height: 1ex; }
/* width of the "0" in the elementā€™s font */
body { line-height: 1ch; }
/* font size of the root element */
body { line-height: 1rem; }
/* VIEWPORT PERCENTAGE LENGTHS */
/* 1% of viewportā€™s width */
body { line-height: 1vw; }
/* 1% of viewportā€™s height */
body { line-height: 1vh; }
/* 1% of viewportā€™s smaller dimension */
body { line-height: 1vmin; }
/* 1% of viewportā€™s larger dimension */
body { line-height: 1vmax; }
/* ABSOLUTE LENGTHS */
/* pixels */
body { line-height: 1px; }
/* millimeters */
body { line-height: 1mm; }
/* quarter-millimeters */
body { line-height: 1q; }
/* centimeters */
body { line-height: 1cm; }
/* inches */
body { line-height: 1in; }
/* points */
body { line-height: 1pt; }
/* picas */
body { line-height: 1pc; }
Option 5: Line-height can be
speciļ¬ed using a number value
(a unit-less value).
body { line-height: 1; }
Number values can be speciļ¬ed
in a range of different ways, as
long as they are positive
values.
/* Valid number values for line-height */
body { line-height: 3; }
body { line-height: 3.01; }
body { line-height: .30; }
body { line-height: .3; }
body { line-height: 0; }
body { line-height: 0.0; }
body { line-height: -0.0; }
body { line-height: +0.0; }
Shorthand
These ļ¬ve line-height values can
also be speciļ¬ed using the ā€Ø
font shorthand property.
The line-height value is written in
conjunction with the font-size
value - separated by a slash:ā€Ø
<font-size>/<line-height>
https://www.w3.org/TR/CSS2/fonts.html#font-shorthand
<'font'> = [ [ <'font-style'> || <'font-variant'>
|| <'font-weight'> ]? <'font-size'> [ / <'line-
height'> ]? <'font-family'> ] | caption | icon |
menu | message-box | small-caption | status-bar |
inherit
body {
font: 1em/normal arial, helvetica, sans-serif;
}
body {
font: 1em/inherit arial, helvetica, sans-serif;
}
body {
font: 1em/20px arial, helvetica, sans-serif;
}
body {
font: 1em/120% arial, helvetica, sans-serif;
}
body {
font: 1em/1.2 arial, helvetica, sans-serif;
}
Inheritance
Some CSS properties are
inherited - which means that
their values are passed down to ā€Ø
descendant elements.
For the line-height property,
inheritance is a little more
complicated than many other
properties.
To see how line-height
inheritance works, we will use
four examples where the line-
height is set on the body only.
Percentage line-height
In the following example, the
line-height for the body element
has been set with a
percentage value (120%).
body {
font-size: 16px;
line-height: 120%;
}
h1 { font-size: 32px; }
p { font-size: 16px; }
footer { font-size: 12px; }
The percentage value and the
body elementā€™s font size are
used to create a calculated
value (16px x 120% = 19.2px).
This calculated value is
inherited by descendant
elements.
body 16px 120% 16 x 120% = 19.2px
h1 32px inherits calculated value 19.2px
p 16px inherits calculated value 19.2px
footer 12px inherits calculated value 19.2px
This results in a line-height which
is acceptable for paragraph
content, but too tight for
headings and too open for the
footer text.
Length line-height
In the following example, the
line-height for the body element
has been set with a length
value (20px).
body {
font-size: 16px;
line-height: 20px;
}
h1 { font-size: 32px; }
p { font-size: 16px; }
footer { font-size: 12px; }
The length value (20px) is
inherited directly by descendant
elements.
body 16px 20px 20px
h1 32px inherits 20px 20px
p 16px inherits 20px 20px
footer 12px inherits 20px 20px
Again, this results in a line-height
which is acceptable for
paragraph content, but too tight
for headings and too open for
the footer text.
Normal line-height
In the following example, the
line-height for the body element
has been set with the
ā€œnormalā€ value.
body {
font-size: 16px;
line-height: normal;
}
h1 { font-size: 32px; }
p { font-size: 16px; }
footer { font-size: 12px; }
In this case, the normal value
rather than a calculated value is
inherited by descendant
elements. Browsers may
interpret the actual normal value
in slightly different ways.
body 16px normal 16 x 1.2 (approx.) = 19.2px (approx.)
h1 32px normal 32 x 1.2 (approx.) = 38.4px (approx.)
p 16px normal 16 x 1.2 (approx.) = 19.2px (approx.)
footer 12px normal 12 x 1.2 (approx.) = 14.4px (approx.)
This method scales the line-
height to suit each element. This
results in a line-height which is
acceptable for the paragraph,
heading and footer content.
Number line-height
In the following example, the
line-height for the body element
has been set with a number
value (1.2).
body {
font-size: 16px;
line-height: 1.2;
}
h1 { font-size: 32px; }
p { font-size: 16px; }
footer { font-size: 12px; }
In this case, the factor (1.2)
rather than a calculated value is
inherited by descendant
elements.
body 16px 1.2 16 x 1.2 = 19.2px
h1 32px factor of 1.2 32 x 1.2 = 38.4px
p 16px factor of 1.2 16 x 1.2 = 19.2px
footer 12px factor of 1.2 12 x 1.2 = 14.4px
Like the normal value, this
method scales to suit each
element and results in a line-
height which is acceptable for
the paragraph, heading and
footer content.
Which method is best?
Number values are the
preferred method as they work
well when inherited.
Unlike the ā€œnormalā€ keyword,
number values allows us to set
speciļ¬c line-heights for
diļ¬€erent types of elements.
Inline boxes and
line-height
Types of boxes
In order to understand ā€Ø
line-height more fully, we need to
look at various types of CSS
boxes.
If we look at a simple
paragraph of text, there are a
range of possible boxes that are
relevant.
The paragraph is referred to as a
containing box in this case - as
it contains other boxes.
The paragraph can also be
referred to as a block box as it
displays as a block - with
whitespace before and after.
containing box
or block box
Inside the paragraph, there may
be any number of inline boxes.
These are boxes that do not
form new lines like block boxes.
In our example, the italic
element is an inline box.
inline box
Other inline boxes without
speciļ¬c markup are referred to
as anonymous inline boxes.
anonymous boxes
Inline boxes sit side-by-side
within the containing box,
forming line boxes.
line boxes
Weā€™ll be looking at line boxes in
more detail later.
The content area is the invisible
box that surrounds the text. Its
height is determined by the font-
size.
ƙAbcdefghijkl
content area
inline box
How line-height aļ¬€ects
inline boxes
Line height is applied to inline
boxes using a simple formula:
Step 1.
Find the difference between the
font-size and line-height. This will
determine the leading.
line-height - font-size = leading
20px - 16px = 4px
Step 2.
Divide the leading in half to
create a ā€œhalf-leadingā€ value.
leading / 2 = half-leading
4px / 2 = 2px (half-leading)
Step 3.
Apply this half-leading value to
the top and bottom of the
content area.
Top half-leading: 2px
Content area: 16pxā€Ø
Bottom half-leading: 2px
Total height: 20px
ƙAbcdefghijkl
inline box = 20px high
top half-leading = 2px high
bottom half-leading = 2px high
content area = 16px high
However, if the line-height is
smaller than the font size, the
inline box will be the height of
the line height only.
This means the content area will
poke out the top and bottom
of the inline box.
line-height - font-size = leading
12px - 16px = -4px (leading)
-4px / 2 = -2px (half-leading)
Top half-leading: -2px
Content area: 16pxā€Ø
Bottom half-leading: -2px
Total height: 12px
ƙAbcdefghijkl
inline box = 12px high
top half-leading = -2px high
bottom half-leading = -2px high
content area = 16px high
Finally, you can also set the
line-height to ā€œ0ā€ which means
the inline element will have no
height at all.
line-height - font-size = leading
0 - 16px = -16px (leading)
-16px / 2 = -8px (half-leading)
Top half-leading: -8px
Content area: 16pxā€Ø
Bottom half-leading: -8px
Total height: 0
ƙAbcdefghijkl
inline box = 0px high
content area = 16px high
Using line-height to
vertically align content
Line-height can be used to
vertically align content inside a
parent container as long as the
content is one line only.
For example:ā€Ø
Letā€™s take a small piece of text
with font-size 16px and we want
it to to be vertically aligned inside
a parent that is 200px high.
We can set the line-height to
200px and this text will
automatically sit in the vertical
centre of the parent.
line-height - font-size = leading
200px - 16px = 184px (leading)
184px / 2 = 92px (half-leading)
Top half-leading: 92px
Content area: 16pxā€Ø
Bottom half-leading: 92px
Total height: 200px
ƙAbcdefghijkl
inline box = 200px
top half-leading = 92px
bottom half-leading = 92px
content area = 16px
Line boxes
How inline boxes aļ¬€ect
line boxes
The height of line boxes is
determined by the tallest inline
box (or replaced element) inside
the line.
The tallest inline box could be an
anonymous inline box.
Some text in a line
line box
anonymous inline box
top half-leading
bottom half-leading
It could be an inline box with
increased line-height (which
makes this inline box taller than
other inline boxes).
Some text
line box
X here
inline box with
increased line-height
It could be an inline box with a
larger font-size (which makes
this inline box taller than other
inline boxes).
Some text
line box
X here
inline box with
increased font-size
Depending on the browser, it
could be the presence of a
superscript or subscript.
(Some browsers render
superscript elements in a way
that affects line boxes)
Some text
line box
2
here
superscript inline box
Side note:
We can solve this by setting the
sup and sub elements with line-
height set to ā€œ0ā€.
sub,
sup {
line-height: 0;
}
Or even the presence of a
replaced element that is larger
than the text around it, such as
an image.
Some text
line box
here
replaced element
anonymous inline box
Inline boxes poking out
of line boxes?
Line boxes are laid out one
after the other, spreading to
the width of the containing box.
Some text that spreads over about
three different lines in a small set of
line boxes
As we have seen, line boxes will
grow to the height of inline
boxes inside.
three different lines in a small set of
Some text that spreads over about
line boxes
inline box with
increased font-size
However, there are times when
aspects of inline boxes will
poke out of the top and/or
bottom of line boxes.
An example is an inline box with
padding, margin or border.
Because inline boxes cannot
be given height, padding,
margin and border can be
present above and below the
element, but they do not affect
the line box.
Some text here
inline box padding
pokes out of line box
Browsers will render the line
boxes in document order. So,
borders on subsequent lines
may paint over the borders
and text of previous lines.
Some text that spreads over about
three different lines in a small set of
line boxes in a paragraph.
paints over previous line
paints over previous line
Ideal ā€Ø
line-height?
The concept of ā€œideal line-
heightā€ depends on a wide
range of factors including the
element, the type of content, and
the column width.
For this reason, Iā€™m only going to
touch on suggested line-hight for
a small set of elements, in
speciļ¬c circumstances.
Research has shown that line-
height that is too small can
make content harder to read
as users have to work harder to
move from line to line.
Similarly, line-height that is too
large can force users eyes
have to travel further to read
content, which can become
tiring.
The WCAG 2.0 guidelines state
that: ā€œline spacing is at least
space-and-a-half within
paragraphsā€.
https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-
contrast-visual-presentation.html
This means that general content
such as paragraphs should be
set to a line-height of 1.5.
p { line-height: 1.5; }
The same rules should apply to
ordered and unordered lists
which have a lot of content
inside each list item.
li { line-height: 1.5; }
However, content-heavy list
items could then bleed into each
other, so you might want to add
additional space after list
items.
li {
line-height: 1.5;
margin-botton: .5em;
}
On the other hand, headings
often look strange when there
is too much line-height, so I
generally set headings to 1.1 or
1.2 - much tighter than
paragraphs.
h1,h2,h3,h4,h5,h6 {
line-height: 1.1;
}
Responsive line-
height?
Several years ago, I was involved
in user testing a content-heavy
website where we wanted the
content to be ā€œas readable as
possibleā€ at all screen sizes.
We tested a range of diļ¬€erent
factors including font-family,
font-size, color and line-height.
As well as testing speciļ¬c tasks,
and recording times for these
tasks, we also asked users
directly about these factors
after each test was concluded.
It turned out that users were
reasonably comfortable with
paragraphs and lists that were
anywhere from 1.4 - 1.6 at
large and mid screen sizes.
However, users were more
comfortable with slightly less
line-height (between 1.3 - 1.5)
at small screen size, as the
lines were much shorter.
As long as line-height is set
using number values, it is very
easy to tweak line-heights for
the diļ¬€erent screen sizes.
p,li { line-height: 1.4; }
@media(min-width: 320px) {
p,li { line-height: 1.5; }
}
Baseline grids
ā€œVertical rhythmā€ in multiple
column layouts is where you to
establish a baseline grid that
aligns across multiple columns
No numquam interpretaris duo. Ei pri nullam
sanctus, sea ornatus probatus pertinax an.
Saepe persius delectus cum eu, ea vim
numquam electram aliquando. Et eos erat
dolorem abhorreant, quem stet vidit te per.
Inermis nonumes mei no, et has ornatus
antiopam cotidieque.
Subheading
Ut sit paulo consulatu, mea nonumy appareat
conceptam et. Dicat consulatu hendrerit duo at,
ei sea tation antiopam accommodare. Eam ad
perfecto imperdiet, novum solet eu mei. Eu eam
aliquam consulatu instructior, vel vocibus
oportere intellegebat ex.
Heading Level 1
Lorem ipsum dolor sit amet, has id discere
platonem ocurreret, ut duo audire senserit
maiestatis, per ex assum instructior. Quo assum
facete deleniti ne. Ei pri nisl voluptatum.
Amet laboramus sententiae te usu. Et cum quis
amet veniam, mel case omittam id, ei vis atqui.
Te munere audire sit, cu sea vidisse probatus,
munere molestie voluptatibus id ius. Paulo
intellegebat has id. Nam no graecis fastidii
perfecto, nec ut atomorum salutatus. Usu at
rebum zril principes, hinc esse id cum. Nam
ridens ullamcorper et.
Using Desktop Publishing
software, this can easily be
achieved by simply checking a
ā€œsnap to baseline gridsā€
button.
However, itā€™s much harder
using CSS. Here are some
steps to achieve a simple
baseline grid.
Step 1.
Set a line-height which will
become the baseline grid.
16px / 24px
$baseline: 24px;
Step 2. ā€Ø
Set headings, paragraphs and
lists with this line-height.
$baseline: 24px;
h1 {
line-height: $basefont*2;
}
p {
line-height: $baseline;
}
Step 3. ā€Ø
Turn off margin-top on all of
these elements, and set the
margin-bottom to match the line-
height. This will set consistent
one full line gaps after each
element.
No numquam interpretaris duo. Ei pri nullam
sanctus, sea ornatus probatus pertinax an.
Saepe persius delectus cum eu, ea vim
numquam electram aliquando. Et eos erat
dolorem abhorreant, quem stet vidit te per.
Inermis nonumes mei no, et has ornatus
antiopam cotidieque.
Subheading
Ut sit paulo consulatu, mea nonumy appareat
conceptam et. Dicat consulatu hendrerit duo at,
ei sea tation antiopam accommodare. Eam ad
perfecto imperdiet, novum solet eu mei. Eu eam
aliquam consulatu instructior, vel vocibus
oportere intellegebat ex.
Heading Level 1
Lorem ipsum dolor sit amet, has id discere
platonem ocurreret, ut duo audire senserit
maiestatis, per ex assum instructior. Quo assum
facete deleniti ne. Ei pri nisl voluptatum.
Amet laboramus sententiae te usu. Et cum quis
amet veniam, mel case omittam id, ei vis atqui.
Te munere audire sit, cu sea vidisse probatus,
munere molestie voluptatibus id ius. Paulo
intellegebat has id. Nam no graecis fastidii
perfecto, nec ut atomorum salutatus. Usu at
rebum zril principes, hinc esse id cum. Nam
ridens ullamcorper et.
$baseline: 24px;
h1 {
line-height: $basefont*2;
margin-bottom: $baseline;
}
p {
line-height: $baseline;
margin-bottom: $baseline;
}
Step 4. ā€Ø
You may need to set font-sizes
to the same ratios.
$basefont: 16px;
$baseline: 24px;
h1 {
line-height: $basefont*2;
margin-bottom: $baseline;
}
p {
font-size: $basefont;
line-height: $baseline;
margin-bottom: $baseline;
}
However, nothing is ever that
simple. As soon as you
introduce pull-quotes, different
headings, special content and
images, things can quickly break
down.
https://www.smashingmagazine.com/2012/12/css-baseline-the-good-
the-bad-and-the-ugly/
http://webdesign.tutsplus.com/articles/setting-web-type-to-a-baseline-
grid--webdesign-3414
http://alistapart.com/article/settingtypeontheweb
http://stephanecurzi.me/baselinecss.2009/grid.html
Conclusion
Line-height is everywhere in
our layouts. Itā€™s in our headings,
in our nav items, our form
controls, our buttons.
Understanding how line-height
works will make your job a lot
easier.
Weā€™re done.
Russ Weakley
Max Design

Site: maxdesign.com.au

Twitter: twitter.com/russmaxdesign

Slideshare: slideshare.net/maxdesign

Linkedin: linkedin.com/in/russweakley

More Related Content

Viewers also liked

Building Accessible Web Components
Building Accessible Web ComponentsBuilding Accessible Web Components
Building Accessible Web ComponentsRuss Weakley
Ā 
JavaScript and Accessibility: Creating Interface Magic for Everyone
JavaScript and Accessibility: Creating Interface Magic for EveryoneJavaScript and Accessibility: Creating Interface Magic for Everyone
JavaScript and Accessibility: Creating Interface Magic for EveryoneDerek Featherstone
Ā 
Clinique ergonomie-accessibilite
Clinique ergonomie-accessibiliteClinique ergonomie-accessibilite
Clinique ergonomie-accessibiliteAccessibilitƩWeb
Ā 
Accessible design: which everyone do you mean? CSUN 2015
Accessible design: which everyone do you mean? CSUN 2015Accessible design: which everyone do you mean? CSUN 2015
Accessible design: which everyone do you mean? CSUN 2015Derek Featherstone
Ā 
Diving into the deep end: SVG, Angular and Accessibility
Diving into the deep end: SVG, Angular and AccessibilityDiving into the deep end: SVG, Angular and Accessibility
Diving into the deep end: SVG, Angular and AccessibilityDerek Featherstone
Ā 
Ergonomie accessibilite-contenus-web
Ergonomie accessibilite-contenus-webErgonomie accessibilite-contenus-web
Ergonomie accessibilite-contenus-webAccessibilitƩWeb
Ā 
Make your content accessible
Make your content accessibleMake your content accessible
Make your content accessibleDerek Featherstone
Ā 
WCAG 2.0: Why can't we all just get along?
WCAG 2.0: Why can't we all just get along?WCAG 2.0: Why can't we all just get along?
WCAG 2.0: Why can't we all just get along?AccessibilitƩWeb
Ā 
Accessibility: Ed Directions North
Accessibility: Ed Directions NorthAccessibility: Ed Directions North
Accessibility: Ed Directions NorthDerek Featherstone
Ā 
Accessibility as a Design Tool
Accessibility as a Design ToolAccessibility as a Design Tool
Accessibility as a Design ToolDerek Featherstone
Ā 
EOTW 2011 Closing Keynote
EOTW 2011 Closing Keynote EOTW 2011 Closing Keynote
EOTW 2011 Closing Keynote Derek Featherstone
Ā 
Integrating accessibility in the organization's web development lifecycle
Integrating accessibility in the organization's web development lifecycleIntegrating accessibility in the organization's web development lifecycle
Integrating accessibility in the organization's web development lifecycleAccessibilitƩWeb
Ā 
Automatic Testing: What can be tested and how?
Automatic Testing: What can be tested and how?Automatic Testing: What can be tested and how?
Automatic Testing: What can be tested and how?Karl Groves
Ā 
Viking methodology
Viking methodologyViking methodology
Viking methodologyKarl Groves
Ā 
Hosting Personal R&D Mandates in Support of Company's R&D Road Map and Intern...
Hosting Personal R&D Mandates in Support of Company's R&D Road Map and Intern...Hosting Personal R&D Mandates in Support of Company's R&D Road Map and Intern...
Hosting Personal R&D Mandates in Support of Company's R&D Road Map and Intern...imec
Ā 
Keputusan
KeputusanKeputusan
KeputusanSunaryo Dk
Ā 
Weight gain after 40 smg template
Weight gain after 40 smg templateWeight gain after 40 smg template
Weight gain after 40 smg templateSummit Health
Ā 
Dinner with Friends
Dinner with FriendsDinner with Friends
Dinner with FriendsInnerHelper
Ā 
Diploma ā€“ successful parts selling
Diploma ā€“ successful parts sellingDiploma ā€“ successful parts selling
Diploma ā€“ successful parts sellingAdam Bradley
Ā 

Viewers also liked (20)

Building Accessible Web Components
Building Accessible Web ComponentsBuilding Accessible Web Components
Building Accessible Web Components
Ā 
JavaScript and Accessibility: Creating Interface Magic for Everyone
JavaScript and Accessibility: Creating Interface Magic for EveryoneJavaScript and Accessibility: Creating Interface Magic for Everyone
JavaScript and Accessibility: Creating Interface Magic for Everyone
Ā 
Clinique ergonomie-accessibilite
Clinique ergonomie-accessibiliteClinique ergonomie-accessibilite
Clinique ergonomie-accessibilite
Ā 
Accessible design: which everyone do you mean? CSUN 2015
Accessible design: which everyone do you mean? CSUN 2015Accessible design: which everyone do you mean? CSUN 2015
Accessible design: which everyone do you mean? CSUN 2015
Ā 
Diving into the deep end: SVG, Angular and Accessibility
Diving into the deep end: SVG, Angular and AccessibilityDiving into the deep end: SVG, Angular and Accessibility
Diving into the deep end: SVG, Angular and Accessibility
Ā 
Ergonomie accessibilite-contenus-web
Ergonomie accessibilite-contenus-webErgonomie accessibilite-contenus-web
Ergonomie accessibilite-contenus-web
Ā 
Make your content accessible
Make your content accessibleMake your content accessible
Make your content accessible
Ā 
WCAG 2.0: Why can't we all just get along?
WCAG 2.0: Why can't we all just get along?WCAG 2.0: Why can't we all just get along?
WCAG 2.0: Why can't we all just get along?
Ā 
Accessibility: Ed Directions North
Accessibility: Ed Directions NorthAccessibility: Ed Directions North
Accessibility: Ed Directions North
Ā 
Accessibility as a Design Tool
Accessibility as a Design ToolAccessibility as a Design Tool
Accessibility as a Design Tool
Ā 
EOTW 2011 Closing Keynote
EOTW 2011 Closing Keynote EOTW 2011 Closing Keynote
EOTW 2011 Closing Keynote
Ā 
Integrating accessibility in the organization's web development lifecycle
Integrating accessibility in the organization's web development lifecycleIntegrating accessibility in the organization's web development lifecycle
Integrating accessibility in the organization's web development lifecycle
Ā 
Automatic Testing: What can be tested and how?
Automatic Testing: What can be tested and how?Automatic Testing: What can be tested and how?
Automatic Testing: What can be tested and how?
Ā 
Viking methodology
Viking methodologyViking methodology
Viking methodology
Ā 
Hosting Personal R&D Mandates in Support of Company's R&D Road Map and Intern...
Hosting Personal R&D Mandates in Support of Company's R&D Road Map and Intern...Hosting Personal R&D Mandates in Support of Company's R&D Road Map and Intern...
Hosting Personal R&D Mandates in Support of Company's R&D Road Map and Intern...
Ā 
Keputusan
KeputusanKeputusan
Keputusan
Ā 
Weight gain after 40 smg template
Weight gain after 40 smg templateWeight gain after 40 smg template
Weight gain after 40 smg template
Ā 
Dinner with Friends
Dinner with FriendsDinner with Friends
Dinner with Friends
Ā 
Diploma ā€“ successful parts selling
Diploma ā€“ successful parts sellingDiploma ā€“ successful parts selling
Diploma ā€“ successful parts selling
Ā 
Preguntas tejada
Preguntas tejadaPreguntas tejada
Preguntas tejada
Ā 

Similar to Deep Dive into Line-Height

CSS LINE HEIGHT
CSS LINE HEIGHTCSS LINE HEIGHT
CSS LINE HEIGHTAnuradha
Ā 
CSS3 notes
CSS3 notesCSS3 notes
CSS3 notesRex Wang
Ā 
CSS Cascade Style Sheet
CSS Cascade Style SheetCSS Cascade Style Sheet
CSS Cascade Style SheetAdeel Rasheed
Ā 
basics of css
basics of cssbasics of css
basics of cssPriya Goyal
Ā 
The Right Layout Tool for the Job
The Right Layout Tool for the JobThe Right Layout Tool for the Job
The Right Layout Tool for the JobRachel Andrew
Ā 
CSS Notes in PDF, Easy to understand. For beginner to advanced. ...
CSS Notes in PDF, Easy to understand. For beginner to advanced.              ...CSS Notes in PDF, Easy to understand. For beginner to advanced.              ...
CSS Notes in PDF, Easy to understand. For beginner to advanced. ...syedfaisal759877
Ā 
CSS Basic and Common Errors
CSS Basic and Common ErrorsCSS Basic and Common Errors
CSS Basic and Common ErrorsHock Leng PUAH
Ā 
Responsive Web Design & Typography
Responsive Web Design & TypographyResponsive Web Design & Typography
Responsive Web Design & TypographyDanny Calders
Ā 
cascading style sheet ppt
cascading style sheet pptcascading style sheet ppt
cascading style sheet pptabhilashagupta
Ā 
Cascading style sheets (CSS-Web Technology)
Cascading style sheets (CSS-Web Technology)Cascading style sheets (CSS-Web Technology)
Cascading style sheets (CSS-Web Technology)Timbal Mayank
Ā 
Pemrograman Web 3 - CSS Basic Part 2
Pemrograman Web 3 - CSS Basic Part 2Pemrograman Web 3 - CSS Basic Part 2
Pemrograman Web 3 - CSS Basic Part 2Nur Fadli Utomo
Ā 

Similar to Deep Dive into Line-Height (20)

CSS LINE HEIGHT
CSS LINE HEIGHTCSS LINE HEIGHT
CSS LINE HEIGHT
Ā 
Web Layout
Web LayoutWeb Layout
Web Layout
Ā 
CSS3 notes
CSS3 notesCSS3 notes
CSS3 notes
Ā 
CSS Cascade Style Sheet
CSS Cascade Style SheetCSS Cascade Style Sheet
CSS Cascade Style Sheet
Ā 
Css Ppt
Css PptCss Ppt
Css Ppt
Ā 
basics of css
basics of cssbasics of css
basics of css
Ā 
The Right Layout Tool for the Job
The Right Layout Tool for the JobThe Right Layout Tool for the Job
The Right Layout Tool for the Job
Ā 
CSS Notes in PDF, Easy to understand. For beginner to advanced. ...
CSS Notes in PDF, Easy to understand. For beginner to advanced.              ...CSS Notes in PDF, Easy to understand. For beginner to advanced.              ...
CSS Notes in PDF, Easy to understand. For beginner to advanced. ...
Ā 
CSS Basic and Common Errors
CSS Basic and Common ErrorsCSS Basic and Common Errors
CSS Basic and Common Errors
Ā 
Basic css
Basic cssBasic css
Basic css
Ā 
Responsive Web Design & Typography
Responsive Web Design & TypographyResponsive Web Design & Typography
Responsive Web Design & Typography
Ā 
CSS
CSSCSS
CSS
Ā 
cascading style sheet ppt
cascading style sheet pptcascading style sheet ppt
cascading style sheet ppt
Ā 
CSS ppt
CSS pptCSS ppt
CSS ppt
Ā 
Css
CssCss
Css
Ā 
Css
CssCss
Css
Ā 
Css
CssCss
Css
Ā 
Cascading style sheets (CSS-Web Technology)
Cascading style sheets (CSS-Web Technology)Cascading style sheets (CSS-Web Technology)
Cascading style sheets (CSS-Web Technology)
Ā 
Css
CssCss
Css
Ā 
Pemrograman Web 3 - CSS Basic Part 2
Pemrograman Web 3 - CSS Basic Part 2Pemrograman Web 3 - CSS Basic Part 2
Pemrograman Web 3 - CSS Basic Part 2
Ā 

More from Russ Weakley

Accessible chat windows
Accessible chat windowsAccessible chat windows
Accessible chat windowsRuss Weakley
Ā 
Accessible names & descriptions
Accessible names & descriptionsAccessible names & descriptions
Accessible names & descriptionsRuss Weakley
Ā 
A deep dive into accessible names
A deep dive into accessible namesA deep dive into accessible names
A deep dive into accessible namesRuss Weakley
Ā 
What are accessible names and why should you care?
What are accessible names and why should you care?What are accessible names and why should you care?
What are accessible names and why should you care?Russ Weakley
Ā 
How to build accessible UI components
How to build accessible UI componentsHow to build accessible UI components
How to build accessible UI componentsRuss Weakley
Ā 
What is WCAG 2 and why should we care?
What is WCAG 2 and why should we care?What is WCAG 2 and why should we care?
What is WCAG 2 and why should we care?Russ Weakley
Ā 
Accessible states in Design Systems
Accessible states in Design SystemsAccessible states in Design Systems
Accessible states in Design SystemsRuss Weakley
Ā 
Creating accessible modals and autocompletes
Creating accessible modals and autocompletesCreating accessible modals and autocompletes
Creating accessible modals and autocompletesRuss Weakley
Ā 
Building an accessible progressive loader
Building an accessible progressive loaderBuilding an accessible progressive loader
Building an accessible progressive loaderRuss Weakley
Ā 
Accessibility in Design systems - the pain and glory
Accessibility in Design systems - the pain and gloryAccessibility in Design systems - the pain and glory
Accessibility in Design systems - the pain and gloryRuss Weakley
Ā 
Accessible Inline errors messages
Accessible Inline errors messagesAccessible Inline errors messages
Accessible Inline errors messagesRuss Weakley
Ā 
Accessible Form Hints and Errors
Accessible Form Hints and ErrorsAccessible Form Hints and Errors
Accessible Form Hints and ErrorsRuss Weakley
Ā 
What is accessibility?
What is accessibility?What is accessibility?
What is accessibility?Russ Weakley
Ā 
Accessibility in Pattern Libraries
Accessibility in Pattern LibrariesAccessibility in Pattern Libraries
Accessibility in Pattern LibrariesRuss Weakley
Ā 
Accessibility in pattern libraries
Accessibility in pattern librariesAccessibility in pattern libraries
Accessibility in pattern librariesRuss Weakley
Ā 
Building an accessible auto-complete - #ID24
Building an accessible auto-complete - #ID24Building an accessible auto-complete - #ID24
Building an accessible auto-complete - #ID24Russ Weakley
Ā 
Building an accessible auto-complete
Building an accessible auto-completeBuilding an accessible auto-complete
Building an accessible auto-completeRuss Weakley
Ā 
Creating Acessible floating labels
Creating Acessible floating labelsCreating Acessible floating labels
Creating Acessible floating labelsRuss Weakley
Ā 
Creating an Accessible button dropdown
Creating an Accessible button dropdownCreating an Accessible button dropdown
Creating an Accessible button dropdownRuss Weakley
Ā 
Creating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off SwitchCreating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off SwitchRuss Weakley
Ā 

More from Russ Weakley (20)

Accessible chat windows
Accessible chat windowsAccessible chat windows
Accessible chat windows
Ā 
Accessible names & descriptions
Accessible names & descriptionsAccessible names & descriptions
Accessible names & descriptions
Ā 
A deep dive into accessible names
A deep dive into accessible namesA deep dive into accessible names
A deep dive into accessible names
Ā 
What are accessible names and why should you care?
What are accessible names and why should you care?What are accessible names and why should you care?
What are accessible names and why should you care?
Ā 
How to build accessible UI components
How to build accessible UI componentsHow to build accessible UI components
How to build accessible UI components
Ā 
What is WCAG 2 and why should we care?
What is WCAG 2 and why should we care?What is WCAG 2 and why should we care?
What is WCAG 2 and why should we care?
Ā 
Accessible states in Design Systems
Accessible states in Design SystemsAccessible states in Design Systems
Accessible states in Design Systems
Ā 
Creating accessible modals and autocompletes
Creating accessible modals and autocompletesCreating accessible modals and autocompletes
Creating accessible modals and autocompletes
Ā 
Building an accessible progressive loader
Building an accessible progressive loaderBuilding an accessible progressive loader
Building an accessible progressive loader
Ā 
Accessibility in Design systems - the pain and glory
Accessibility in Design systems - the pain and gloryAccessibility in Design systems - the pain and glory
Accessibility in Design systems - the pain and glory
Ā 
Accessible Inline errors messages
Accessible Inline errors messagesAccessible Inline errors messages
Accessible Inline errors messages
Ā 
Accessible Form Hints and Errors
Accessible Form Hints and ErrorsAccessible Form Hints and Errors
Accessible Form Hints and Errors
Ā 
What is accessibility?
What is accessibility?What is accessibility?
What is accessibility?
Ā 
Accessibility in Pattern Libraries
Accessibility in Pattern LibrariesAccessibility in Pattern Libraries
Accessibility in Pattern Libraries
Ā 
Accessibility in pattern libraries
Accessibility in pattern librariesAccessibility in pattern libraries
Accessibility in pattern libraries
Ā 
Building an accessible auto-complete - #ID24
Building an accessible auto-complete - #ID24Building an accessible auto-complete - #ID24
Building an accessible auto-complete - #ID24
Ā 
Building an accessible auto-complete
Building an accessible auto-completeBuilding an accessible auto-complete
Building an accessible auto-complete
Ā 
Creating Acessible floating labels
Creating Acessible floating labelsCreating Acessible floating labels
Creating Acessible floating labels
Ā 
Creating an Accessible button dropdown
Creating an Accessible button dropdownCreating an Accessible button dropdown
Creating an Accessible button dropdown
Ā 
Creating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off SwitchCreating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off Switch
Ā 

Recently uploaded

Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
Ā 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
Ā 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
Ā 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
Ā 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
Ā 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
Ā 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
Ā 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
Ā 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
Ā 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
Ā 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
Ā 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
Ā 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
Ā 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
Ā 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
Ā 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
Ā 

Recently uploaded (20)

Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Ā 
Model Call Girl in Tilak Nagar Delhi reach out to us at šŸ”9953056974šŸ”
Model Call Girl in Tilak Nagar Delhi reach out to us at šŸ”9953056974šŸ”Model Call Girl in Tilak Nagar Delhi reach out to us at šŸ”9953056974šŸ”
Model Call Girl in Tilak Nagar Delhi reach out to us at šŸ”9953056974šŸ”
Ā 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
Ā 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Ā 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
Ā 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
Ā 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
Ā 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
Ā 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Ā 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
Ā 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
Ā 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
Ā 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
Ā 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
Ā 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
Ā 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
Ā 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
Ā 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
Ā 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
Ā 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
Ā 

Deep Dive into Line-Height

  • 2. Why should you care about line-height?
  • 3. Because line-height is an integral part of CSS-based layouts.
  • 4. It can help to make our content easier to read and comprehend.
  • 5. It can be used to control the vertical rhythm of multiple column layouts.
  • 6. It can be used to centre inline content vertically.
  • 7. But also because it is one of the fundamentals of CSS, like font- sizing, the cascade, inheritance and selectors.
  • 8. But before we begin, let's go back in time and look at the term ā€œleadingā€.
  • 10. Back in the ā€œgood old daysā€ type was set by hand using printing presses.
  • 11. Printed material was created by setting out letters in rows. Each letter was created on anā€Ø individual block.
  • 12.
  • 13. Leading, or lead strips were added between the lines of letters when additional vertical space was required.
  • 14. The term ā€œleadingā€ is still used today in print typography, where it refers to the distance between the baselines of successive lines of type.
  • 15. In CSS, the line-height property is used to control the vertical space between lines.
  • 16. However, as we will soon see, ā€œleadingā€ is still used in association with CSS line-height.
  • 18. The CSS line-height syntax looks like this: https://www.w3.org/TR/CSS2/visudet.html#line-height
  • 19. <'line-height'> = normal | <number> | <length> | <percentage> | inherit
  • 20. This means that line-height can be speciļ¬ed using one of the following methods:
  • 21. Option 1: Line-height can be speciļ¬ed as ā€œnormalā€ which is the initial value. By default, browsers use between 1.0 - 1.2 line-height.
  • 22. body { line-height: normal; }
  • 23. Option 2: Line-height can be speciļ¬ed as ā€œinheritā€ which will inherit the line-height from the parent.
  • 24. body { line-height: inherit; }
  • 25. Option 3: Line-height can be speciļ¬ed using a percentage value.
  • 27. Option 4: Line-height can be speciļ¬ed using a length value.
  • 29. A wide range of diļ¬€erent types of length values can be used such as:
  • 30. /* FONT RELATATIVE LENGTHS */ /* font size of the element */ body { line-height: 1em; } /* x-height of the elementā€™s font */ body { line-height: 1ex; } /* width of the "0" in the elementā€™s font */ body { line-height: 1ch; } /* font size of the root element */ body { line-height: 1rem; }
  • 31. /* VIEWPORT PERCENTAGE LENGTHS */ /* 1% of viewportā€™s width */ body { line-height: 1vw; } /* 1% of viewportā€™s height */ body { line-height: 1vh; } /* 1% of viewportā€™s smaller dimension */ body { line-height: 1vmin; } /* 1% of viewportā€™s larger dimension */ body { line-height: 1vmax; }
  • 32. /* ABSOLUTE LENGTHS */ /* pixels */ body { line-height: 1px; } /* millimeters */ body { line-height: 1mm; } /* quarter-millimeters */ body { line-height: 1q; } /* centimeters */ body { line-height: 1cm; }
  • 33. /* inches */ body { line-height: 1in; } /* points */ body { line-height: 1pt; } /* picas */ body { line-height: 1pc; }
  • 34. Option 5: Line-height can be speciļ¬ed using a number value (a unit-less value).
  • 36. Number values can be speciļ¬ed in a range of different ways, as long as they are positive values.
  • 37. /* Valid number values for line-height */ body { line-height: 3; } body { line-height: 3.01; } body { line-height: .30; } body { line-height: .3; } body { line-height: 0; } body { line-height: 0.0; } body { line-height: -0.0; } body { line-height: +0.0; }
  • 39. These ļ¬ve line-height values can also be speciļ¬ed using the ā€Ø font shorthand property.
  • 40. The line-height value is written in conjunction with the font-size value - separated by a slash:ā€Ø <font-size>/<line-height> https://www.w3.org/TR/CSS2/fonts.html#font-shorthand
  • 41. <'font'> = [ [ <'font-style'> || <'font-variant'> || <'font-weight'> ]? <'font-size'> [ / <'line- height'> ]? <'font-family'> ] | caption | icon | menu | message-box | small-caption | status-bar | inherit
  • 42. body { font: 1em/normal arial, helvetica, sans-serif; }
  • 43. body { font: 1em/inherit arial, helvetica, sans-serif; }
  • 44. body { font: 1em/20px arial, helvetica, sans-serif; }
  • 45. body { font: 1em/120% arial, helvetica, sans-serif; }
  • 46. body { font: 1em/1.2 arial, helvetica, sans-serif; }
  • 48. Some CSS properties are inherited - which means that their values are passed down to ā€Ø descendant elements.
  • 49. For the line-height property, inheritance is a little more complicated than many other properties.
  • 50. To see how line-height inheritance works, we will use four examples where the line- height is set on the body only.
  • 52. In the following example, the line-height for the body element has been set with a percentage value (120%).
  • 53. body { font-size: 16px; line-height: 120%; } h1 { font-size: 32px; } p { font-size: 16px; } footer { font-size: 12px; }
  • 54. The percentage value and the body elementā€™s font size are used to create a calculated value (16px x 120% = 19.2px).
  • 55. This calculated value is inherited by descendant elements.
  • 56. body 16px 120% 16 x 120% = 19.2px h1 32px inherits calculated value 19.2px p 16px inherits calculated value 19.2px footer 12px inherits calculated value 19.2px
  • 57. This results in a line-height which is acceptable for paragraph content, but too tight for headings and too open for the footer text.
  • 58.
  • 60. In the following example, the line-height for the body element has been set with a length value (20px).
  • 61. body { font-size: 16px; line-height: 20px; } h1 { font-size: 32px; } p { font-size: 16px; } footer { font-size: 12px; }
  • 62. The length value (20px) is inherited directly by descendant elements.
  • 63. body 16px 20px 20px h1 32px inherits 20px 20px p 16px inherits 20px 20px footer 12px inherits 20px 20px
  • 64. Again, this results in a line-height which is acceptable for paragraph content, but too tight for headings and too open for the footer text.
  • 65.
  • 67. In the following example, the line-height for the body element has been set with the ā€œnormalā€ value.
  • 68. body { font-size: 16px; line-height: normal; } h1 { font-size: 32px; } p { font-size: 16px; } footer { font-size: 12px; }
  • 69. In this case, the normal value rather than a calculated value is inherited by descendant elements. Browsers may interpret the actual normal value in slightly different ways.
  • 70. body 16px normal 16 x 1.2 (approx.) = 19.2px (approx.) h1 32px normal 32 x 1.2 (approx.) = 38.4px (approx.) p 16px normal 16 x 1.2 (approx.) = 19.2px (approx.) footer 12px normal 12 x 1.2 (approx.) = 14.4px (approx.)
  • 71. This method scales the line- height to suit each element. This results in a line-height which is acceptable for the paragraph, heading and footer content.
  • 72.
  • 74. In the following example, the line-height for the body element has been set with a number value (1.2).
  • 75. body { font-size: 16px; line-height: 1.2; } h1 { font-size: 32px; } p { font-size: 16px; } footer { font-size: 12px; }
  • 76. In this case, the factor (1.2) rather than a calculated value is inherited by descendant elements.
  • 77. body 16px 1.2 16 x 1.2 = 19.2px h1 32px factor of 1.2 32 x 1.2 = 38.4px p 16px factor of 1.2 16 x 1.2 = 19.2px footer 12px factor of 1.2 12 x 1.2 = 14.4px
  • 78. Like the normal value, this method scales to suit each element and results in a line- height which is acceptable for the paragraph, heading and footer content.
  • 79.
  • 81. Number values are the preferred method as they work well when inherited.
  • 82. Unlike the ā€œnormalā€ keyword, number values allows us to set speciļ¬c line-heights for diļ¬€erent types of elements.
  • 85. In order to understand ā€Ø line-height more fully, we need to look at various types of CSS boxes.
  • 86. If we look at a simple paragraph of text, there are a range of possible boxes that are relevant.
  • 87. The paragraph is referred to as a containing box in this case - as it contains other boxes.
  • 88. The paragraph can also be referred to as a block box as it displays as a block - with whitespace before and after.
  • 90. Inside the paragraph, there may be any number of inline boxes. These are boxes that do not form new lines like block boxes.
  • 91. In our example, the italic element is an inline box.
  • 93. Other inline boxes without speciļ¬c markup are referred to as anonymous inline boxes.
  • 95. Inline boxes sit side-by-side within the containing box, forming line boxes.
  • 97. Weā€™ll be looking at line boxes in more detail later.
  • 98. The content area is the invisible box that surrounds the text. Its height is determined by the font- size.
  • 101. Line height is applied to inline boxes using a simple formula:
  • 102. Step 1. Find the difference between the font-size and line-height. This will determine the leading.
  • 103. line-height - font-size = leading 20px - 16px = 4px
  • 104. Step 2. Divide the leading in half to create a ā€œhalf-leadingā€ value.
  • 105. leading / 2 = half-leading 4px / 2 = 2px (half-leading)
  • 106. Step 3. Apply this half-leading value to the top and bottom of the content area.
  • 107. Top half-leading: 2px Content area: 16pxā€Ø Bottom half-leading: 2px Total height: 20px
  • 108. ƙAbcdefghijkl inline box = 20px high top half-leading = 2px high bottom half-leading = 2px high content area = 16px high
  • 109. However, if the line-height is smaller than the font size, the inline box will be the height of the line height only.
  • 110. This means the content area will poke out the top and bottom of the inline box.
  • 111. line-height - font-size = leading 12px - 16px = -4px (leading) -4px / 2 = -2px (half-leading) Top half-leading: -2px Content area: 16pxā€Ø Bottom half-leading: -2px Total height: 12px
  • 112. ƙAbcdefghijkl inline box = 12px high top half-leading = -2px high bottom half-leading = -2px high content area = 16px high
  • 113. Finally, you can also set the line-height to ā€œ0ā€ which means the inline element will have no height at all.
  • 114. line-height - font-size = leading 0 - 16px = -16px (leading) -16px / 2 = -8px (half-leading) Top half-leading: -8px Content area: 16pxā€Ø Bottom half-leading: -8px Total height: 0
  • 115. ƙAbcdefghijkl inline box = 0px high content area = 16px high
  • 117. Line-height can be used to vertically align content inside a parent container as long as the content is one line only.
  • 118. For example:ā€Ø Letā€™s take a small piece of text with font-size 16px and we want it to to be vertically aligned inside a parent that is 200px high.
  • 119. We can set the line-height to 200px and this text will automatically sit in the vertical centre of the parent.
  • 120. line-height - font-size = leading 200px - 16px = 184px (leading) 184px / 2 = 92px (half-leading) Top half-leading: 92px Content area: 16pxā€Ø Bottom half-leading: 92px Total height: 200px
  • 121. ƙAbcdefghijkl inline box = 200px top half-leading = 92px bottom half-leading = 92px content area = 16px
  • 123. How inline boxes aļ¬€ect line boxes
  • 124. The height of line boxes is determined by the tallest inline box (or replaced element) inside the line.
  • 125. The tallest inline box could be an anonymous inline box.
  • 126. Some text in a line line box anonymous inline box top half-leading bottom half-leading
  • 127. It could be an inline box with increased line-height (which makes this inline box taller than other inline boxes).
  • 128. Some text line box X here inline box with increased line-height
  • 129. It could be an inline box with a larger font-size (which makes this inline box taller than other inline boxes).
  • 130. Some text line box X here inline box with increased font-size
  • 131. Depending on the browser, it could be the presence of a superscript or subscript. (Some browsers render superscript elements in a way that affects line boxes)
  • 133. Side note: We can solve this by setting the sup and sub elements with line- height set to ā€œ0ā€.
  • 135. Or even the presence of a replaced element that is larger than the text around it, such as an image.
  • 136. Some text line box here replaced element anonymous inline box
  • 137. Inline boxes poking out of line boxes?
  • 138. Line boxes are laid out one after the other, spreading to the width of the containing box.
  • 139. Some text that spreads over about three different lines in a small set of line boxes
  • 140. As we have seen, line boxes will grow to the height of inline boxes inside.
  • 141. three different lines in a small set of Some text that spreads over about line boxes inline box with increased font-size
  • 142. However, there are times when aspects of inline boxes will poke out of the top and/or bottom of line boxes.
  • 143. An example is an inline box with padding, margin or border.
  • 144. Because inline boxes cannot be given height, padding, margin and border can be present above and below the element, but they do not affect the line box.
  • 145. Some text here inline box padding pokes out of line box
  • 146. Browsers will render the line boxes in document order. So, borders on subsequent lines may paint over the borders and text of previous lines.
  • 147. Some text that spreads over about three different lines in a small set of line boxes in a paragraph. paints over previous line paints over previous line
  • 149. The concept of ā€œideal line- heightā€ depends on a wide range of factors including the element, the type of content, and the column width.
  • 150. For this reason, Iā€™m only going to touch on suggested line-hight for a small set of elements, in speciļ¬c circumstances.
  • 151. Research has shown that line- height that is too small can make content harder to read as users have to work harder to move from line to line.
  • 152. Similarly, line-height that is too large can force users eyes have to travel further to read content, which can become tiring.
  • 153. The WCAG 2.0 guidelines state that: ā€œline spacing is at least space-and-a-half within paragraphsā€. https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio- contrast-visual-presentation.html
  • 154. This means that general content such as paragraphs should be set to a line-height of 1.5.
  • 155. p { line-height: 1.5; }
  • 156. The same rules should apply to ordered and unordered lists which have a lot of content inside each list item.
  • 157. li { line-height: 1.5; }
  • 158. However, content-heavy list items could then bleed into each other, so you might want to add additional space after list items.
  • 160. On the other hand, headings often look strange when there is too much line-height, so I generally set headings to 1.1 or 1.2 - much tighter than paragraphs.
  • 163. Several years ago, I was involved in user testing a content-heavy website where we wanted the content to be ā€œas readable as possibleā€ at all screen sizes.
  • 164. We tested a range of diļ¬€erent factors including font-family, font-size, color and line-height.
  • 165. As well as testing speciļ¬c tasks, and recording times for these tasks, we also asked users directly about these factors after each test was concluded.
  • 166. It turned out that users were reasonably comfortable with paragraphs and lists that were anywhere from 1.4 - 1.6 at large and mid screen sizes.
  • 167. However, users were more comfortable with slightly less line-height (between 1.3 - 1.5) at small screen size, as the lines were much shorter.
  • 168. As long as line-height is set using number values, it is very easy to tweak line-heights for the diļ¬€erent screen sizes.
  • 169. p,li { line-height: 1.4; } @media(min-width: 320px) { p,li { line-height: 1.5; } }
  • 171. ā€œVertical rhythmā€ in multiple column layouts is where you to establish a baseline grid that aligns across multiple columns
  • 172. No numquam interpretaris duo. Ei pri nullam sanctus, sea ornatus probatus pertinax an. Saepe persius delectus cum eu, ea vim numquam electram aliquando. Et eos erat dolorem abhorreant, quem stet vidit te per. Inermis nonumes mei no, et has ornatus antiopam cotidieque. Subheading Ut sit paulo consulatu, mea nonumy appareat conceptam et. Dicat consulatu hendrerit duo at, ei sea tation antiopam accommodare. Eam ad perfecto imperdiet, novum solet eu mei. Eu eam aliquam consulatu instructior, vel vocibus oportere intellegebat ex. Heading Level 1 Lorem ipsum dolor sit amet, has id discere platonem ocurreret, ut duo audire senserit maiestatis, per ex assum instructior. Quo assum facete deleniti ne. Ei pri nisl voluptatum. Amet laboramus sententiae te usu. Et cum quis amet veniam, mel case omittam id, ei vis atqui. Te munere audire sit, cu sea vidisse probatus, munere molestie voluptatibus id ius. Paulo intellegebat has id. Nam no graecis fastidii perfecto, nec ut atomorum salutatus. Usu at rebum zril principes, hinc esse id cum. Nam ridens ullamcorper et.
  • 173. Using Desktop Publishing software, this can easily be achieved by simply checking a ā€œsnap to baseline gridsā€ button.
  • 174. However, itā€™s much harder using CSS. Here are some steps to achieve a simple baseline grid.
  • 175. Step 1. Set a line-height which will become the baseline grid. 16px / 24px
  • 177. Step 2. ā€Ø Set headings, paragraphs and lists with this line-height.
  • 178. $baseline: 24px; h1 { line-height: $basefont*2; } p { line-height: $baseline; }
  • 179. Step 3. ā€Ø Turn off margin-top on all of these elements, and set the margin-bottom to match the line- height. This will set consistent one full line gaps after each element.
  • 180. No numquam interpretaris duo. Ei pri nullam sanctus, sea ornatus probatus pertinax an. Saepe persius delectus cum eu, ea vim numquam electram aliquando. Et eos erat dolorem abhorreant, quem stet vidit te per. Inermis nonumes mei no, et has ornatus antiopam cotidieque. Subheading Ut sit paulo consulatu, mea nonumy appareat conceptam et. Dicat consulatu hendrerit duo at, ei sea tation antiopam accommodare. Eam ad perfecto imperdiet, novum solet eu mei. Eu eam aliquam consulatu instructior, vel vocibus oportere intellegebat ex. Heading Level 1 Lorem ipsum dolor sit amet, has id discere platonem ocurreret, ut duo audire senserit maiestatis, per ex assum instructior. Quo assum facete deleniti ne. Ei pri nisl voluptatum. Amet laboramus sententiae te usu. Et cum quis amet veniam, mel case omittam id, ei vis atqui. Te munere audire sit, cu sea vidisse probatus, munere molestie voluptatibus id ius. Paulo intellegebat has id. Nam no graecis fastidii perfecto, nec ut atomorum salutatus. Usu at rebum zril principes, hinc esse id cum. Nam ridens ullamcorper et.
  • 181. $baseline: 24px; h1 { line-height: $basefont*2; margin-bottom: $baseline; } p { line-height: $baseline; margin-bottom: $baseline; }
  • 182. Step 4. ā€Ø You may need to set font-sizes to the same ratios.
  • 183. $basefont: 16px; $baseline: 24px; h1 { line-height: $basefont*2; margin-bottom: $baseline; } p { font-size: $basefont; line-height: $baseline; margin-bottom: $baseline; }
  • 184. However, nothing is ever that simple. As soon as you introduce pull-quotes, different headings, special content and images, things can quickly break down.
  • 187. Line-height is everywhere in our layouts. Itā€™s in our headings, in our nav items, our form controls, our buttons.
  • 188. Understanding how line-height works will make your job a lot easier.
  • 190. Russ Weakley Max Design Site: maxdesign.com.au Twitter: twitter.com/russmaxdesign Slideshare: slideshare.net/maxdesign Linkedin: linkedin.com/in/russweakley