Skip to Content
HTML & CSS: The Good Parts
book

HTML & CSS: The Good Parts

by Ben Henick
February 2010
Intermediate to advanced
352 pages
11h 4m
English
O'Reilly Media, Inc.
Content preview from HTML & CSS: The Good Parts

CSS Units

While CSS supports a seemingly endless list of properties, the scheme for setting values is fairly predictable. Table 3-2 describes the most frequently used values.

Table 3-2. Commonly encountered CSS length/size, keyword, and color units

Unit

Type

Example

px (pixels)

length

width: 744px;

em (ems)

length

margin-left; 1.25em;

% (percent)

length

left: 34%;

pt (points)

length

font-size: 12pt;

in (inches)

length

margin-top: .75in;

cm (centimeters)

length

margin-top: 1.905cm;

xx-small ... xx-large

font size

font-size: large;

rgb(r,g,b)

color (decimal)

background-color: rgb(221,204,187);

#rrggbb

color (hexadecimal)

background-color: #ddccbb;

#rgb

color (hexadecimal, reduced depth)

background-color: #dcb;

Cross-Media Length and Size Units

There are three commonly used units in stylesheets intended for screen display:

px (pixels)

Pixels are absolute units, equal to one pixel on the user’s screen display; always expressed as an integer.

em (ems)

In digital typesetting environments (including CSS), an em is equivalent to the greatest possible height of a glyph (letter) in the applicable font and size combination. The contemporary definition contrasts with the historical definition: the width of a capital “M” in the font and size of the type to which it is applied as a measurement. This unit is usually expressed with a floating-point value.

% (percent)

Percentage units are computed relative to some baseline measurement, which varies according to property and context. Floating-point percentage values are allowed.

em and

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

HTML & CSS: Design and Build Websites

HTML & CSS: Design and Build Websites

Jon Duckett
Head First HTML and CSS, 2nd Edition

Head First HTML and CSS, 2nd Edition

Elisabeth Robson, Eric Freeman

Publisher Resources

ISBN: 9781449381943Errata Page