CSS Fonts and Formatting
CSS Fonts and Formatting
R. Scott Granneman
Jans Carton
Serif
Sans-serif
Monospaced/Monospaced
Serif font
Sans-serif font
1 x-height 11 counter
2 ascender line 12 collar
3 apex 13 loop
4 baseline 14 ear
5 ascender 15 tie
6 crossbar 16 horizontal bar
7 stem 17 arm
8 serif 18 vertical bar
9 leg 19 cap height
10 bowl 20 descender line
1 x-height 11 counter
2 ascender line 12 collar
3 apex 13 loop
4 baseline 14 ear
5 ascender 15 tie
6 crossbar 16 horizontal bar
7 stem 17 arm
18 serif 18 vertical bar
19 leg 19 cap height
10 bowl 20 descender line
Measure
Measure
~ 65 characters is ideal
Same as:
* {
font: 1em/1.3 Helvetica, sans-serif;
}
Scale
Do not size text arbitrarily
6 7 8 9 10 11 12 14 16 18 21 24
36 48 60 72
Fibonacci sequence scale
8 13 21 34 55 89
The W3 provides a very usable, standard scale
<absolute-size> Scaling Factor HTML hx
xx-large 2/1 <h1>
x-large 3/2 <h2>
large 6/5 <h3>
medium 1 <h4>
small 8/9 <h5>
x-small 3/4
xx-small 3/5 <h6>
body {font: 1em/1.3 "Lucida Grande";}
h1, h2, h3, h4, h5, h6 {font-family: Georgia;}
h1 {font-size: 200%;}
h2 {font-size: 150%;}
h3 {font-size: 120%;}
h4 {font-size: 100%;}
h5 {font-size: 89%;}
h6 {font-size: 60%;}
Common Fonts
& Defaults
Microsoft’s
Core Fonts
for the Web
Provided by Microsoft royalty-free 1996-2002
Still legally available all over the Web & on all Macs
“Arial is just an ugly bastard son of Helvetica.” —King
Sidharth
Still included in Windows
(why?!?)
» Windows Vista
» Office 2007 for Windows
» Office 2008 for Mac OS X
Default body type face in
Word, Excel, PowerPoint,
& Outlook since Office
2007
Default header type face in
Word, Excel, PowerPoint,
& Outlook since Office
2007
Monospaced font that’s
become pretty popular
with developers
O0
1lI
,.;:
Web Browser
Defaults
OS Browser Sans-Serif Serif Monospace
Times Courier
* Windows 7 & up
OS Browser Sans-Serif Serif Mono
Droid Sans
Droid Sans Droid Serif
Mono
line-height
font-style
font-variant
font-weight
font-family
font-size
font-size
Values
» <absolute-size>
» <relative-size>
» <length> data type
» <percentage> data type
<absolute-size> Scaling Factor HTML hx
xx-large 2/1 <h1>
x-large 3/2 <h2>
large 6/5 <h3>
medium 1 <h4>
small 8/9 <h5>
x-small 3/4
xx-small 3/5 <h6>
<relative-size>
larger
smaller
<length>
Units
» Absolute
» Font-relative
» Viewport-percentage
Pixel means
picture element
mm
cm
in
pt
pc
px 96 pixels per inch
mm 1 millimeter
cm 1 centimeter = 10 mm
in 1 inch = 2.54 cm
pt 1 point = 1/72 in
pc 1 pica = 12 pt
Font-Relative <length>
em
ex
ch
rem
ex
x-height of font
1ex ≈ 0.5em
ch
Width of 0 (zero)
em
ex 5.5 1 1 1 1 1
ch 9 — 27 1 — ?
150%
Our recommendation
px for <html>
Values
» normal: Desktop browsers use a default value of roughly
1.2
» <number>: unitless number (e.g., 1.4) is the preferred
method
» <length>: em in particular may be problematic
» <percentage>: may be very problematic
Unitless <number> is the preferred way to set line-
height
font-size: 1em;
line-height: 1.4;
font-style
italic oblique
Cursive Sloped
Values
» normal: Same as 400
» bold: Same as 700
» bolder: 1 font weight darker than parent
» lighter: 1 font weight lighter than parent
» 100–900: Numeric weights from lightest to darkest
Values
» <family-name>: name of a font family, e.g., Lato or
"Iowan Old Style" (quotation marks if spaces!)
» <generic-family>: name of a generic fallback font
family
generic-family can be:
serif
sans-serif
cursive
fantasy
monospace
font-family: cursive
Savoye LET
Snell Roundhand
o
font-family: fantasy
Party LET
Chalkduster
Playbill
Jazz LET
Harrington
Font Stacks
List fonts in the order you want them to be used,
from most specific to generic
OR
text-shadow white-space
letter-spacing word-break
text-decoration direction
text-transform unicode-bidi
font-size, font-weight, font-family, but also text-
decoration, text-transform, & text-indent?
Red-Green-Blue-Alpha rgba(255,0,51,0.7)
Hue-Saturation-Lightness hsl(348,100%,50%)
Hue-Saturation-Lightness-Alpha hsla(348,100%,50%,0.7)
Color keywords
CSS 1: 16
CSS 2: 1
CSS 3: 128
Numeral system
#RRGGBB
#FF0000 → #F00
#33AA77 → #3A7
#BBFF33 → #BF3
#DDEEFF → #DEF
RGB notation
rgb(R,G,B)
Expressed as either:
rgba(R,G,B,A)
rgb(255,0,0) → rgba(255,0,0,0.5)
rgb(0,255,201) → rgba(0,255,201,0.66)
Hue
» color
» integer between 0 & 360
Lightness
» relative degree of black or white mixed with a hue
» percentage between 0 & 100%
May add a 4th place for transparency: alpha channel
hsla(H,S,L,A)
hsl(360,100%,100%) → hsla(360,100%,100%,0.5)
hsl(165,87%,100%) → hsla(165,87%,100%,0.66)
Special keywords
transparent
Fully transparent, the same as rgba(0,0,0,0)
currentcolor
Value of parent element’s color
Instead of this: Use this:
body {
color: #f0f;
}
hr {
height: 10px;
background: currentcolor;
}
body {color: #f0f;}
hr {
height: 10px;
background: currentcolor;
}
word-spacing
Values
» underline: draws a line under text (do not use)
» overline: draws a line above text
» underline overline: draws lines under & above text
» line-through: draws line through text (like <s>)
» none: removes lines (from <a> in particular, but be
careful with this!)
text-transform
Specifies capitalization
Values
» capitalize: capitalize every word (headline case)
» uppercase: capitalize every letter (all caps)
» lowercase: lowercase every letter
» none: do not change capitalization
Typesetter’s sorting case
Values
» <length> data type
» <percentage> data type
p:first-child {text-indent: 1em;}
p:nth-child(2) {
width: 90%;
margin-left: auto;
margin-right: auto;
text-indent: -1em;
}
Line Box
Properties
text-align
Values
» left: align left (default)
» right: align right
» center: center content
» justify: left & right edges of content line up to left &
right edges of container (do not use!)
“Justifying text can present problems for people with
Dyslexia … Another user group affected by text
justification is screen magnification users.
column-count
column-width
column-rule
column-gap
3.1 4 2 2.1 3.2
column-count 10 -webkit- -webkit- -moz- -webkit- -webkit-
W3 Recommendation as of 2012
WOFF2: Web Open Font Format 2.0, AKA WOFF Ultra
Condensed
WOFF2 36 24
SVG 3.1 4 10
@font-face
CSS2 introduced @font-face
@font-face {
font-family: <font-name>;
src: <source>, <source>;
}
src
Location of font
p {
font-family: Foobar, sans-serif;
}
@font-face {
font-family: Foobar;
src: local(Foobar.ttf);
}
Local font on user’s device
p {
font-family: Foobar, sans-serif;
}
Can use any name (value)
for font-family you want
@font-face {
font-family: Foobar;
src: local(Foobar.ttf);
}
Local font on user’s device
p {
font-family: Foobar, sans-serif;
}
@font-face {
font-family: Foobar;
src: url(http://www.fonts.com/foobar.woff);
}
p {
font-family: Foobar, sans-serif;
}
@font-face {
font-family: Foobar;
src: url(http://www.fonts.com/foobar.woff);
}
Remote font downloaded
onto user’s device
p {
font-family: Foobar, sans-serif;
}
@font-face {
font-family: Foobar;
src: local(Foobar.ttf),
url(http://www.fonts.com/foobar.woff);
}
p {
font-family: Foobar, sans-serif;
}
Local AND remote
covers all bases—
@font-face {
but don’t use local!
font-family: Foobar;
src: local(Foobar.ttf),
url(http://www.fonts.com/foobar.woff);
}
p {
font-family: Foobar, sans-serif;
}
Licensing
Problem: unauthorized copying, which type foundries
do not want
Solution:
<style>
h1, h2, h3, h4 {
font-family: Bitter, serif;
}
p {
font-family: “Pontano Sans”, sans-serif;
}
</style>
</head>
<head>
<link rel="stylesheet" href="http://
fonts.googleapis.com/css?family=Bitter:700|
Pontano+Sans&subset=latin-ext">
main.css
@import url(http://fonts.googleapis.com/css?
family=Bitter:400,700|Pontano+Sans);
p {
font-family: “Pontano Sans”, sans-serif;
}
One bad hidden “feature” of Google Fonts
@font-face {
font-family: 'Oswald';
font-style: normal;
font-weight: 400;
src: local('Oswald Regular'), local('Oswald-
Regular'), url(http://fonts.gstatic.com/s/
oswald/v10/Qw6_9HvXRQGg5mMbFR3Phn-
_kf6ByYO6CLYdB4HQE-Y.woff2) format('woff2');
}
If you use Safari to get the code:
@font-face {
font-family: 'Oswald';
font-style: normal;
font-weight: 400;
src: local('Oswald Regular'), local('Oswald-
Regular'), url(http://fonts.gstatic.com/s/
oswald/v10/lXoKq2PC8Z_S1wl-BwvrB-
vvDin1pK8aKteLpeZ5c0A.ttf) format('truetype');
}
If you use Firefox to get the code:
@font-face {
font-family: 'Oswald';
font-style: normal;
font-weight: 400;
src: local('Oswald Regular'), local('Oswald-
Regular'), url(http://fonts.gstatic.com/s/oswald/v10/
_P8jt3Y65hJ9c4AzRE0V1OvvDin1pK8aKteLpeZ5c0A.woff2)
format('woff2'), url(http://fonts.gstatic.com/s/
oswald/v10/qpy-UiLNKP-VfOdbcs6r6-
vvDin1pK8aKteLpeZ5c0A.woff) format('woff');
}
If you use Internet Explorer 11 to get the code:
@font-face {
font-family: 'Oswald';
font-style: normal;
font-weight: 400;
src: local('Oswald Regular'), local('Oswald-
Regular'), url(http://fonts.gstatic.com/s/
oswald/v10/-g5pDUSRgvxvOl5u-a_WHw.woff)
format('woff');
}
To recap:
» WOFF2: 44%
» TTF: 91%
» WOFF: 88%
So always use Firefox when working with Google
Fonts
[email protected]
www.granneman.com
ChainsawOnATireSwing.com
@scottgranneman
[email protected]
websanity.com
Batang
Bonus
The following slides contain extra, bonus information
that we don’t have time to cover in class
Basics
Types
Adobe Type Classifications
Adobe Originals Greek Sans Serif: Grotesque,
Neo-Grotesque,
Blackletter Hand-tooled, Inline, Geometric and Humanist
Outline, Stencil
Capitals Script
Japanese
Computer Related Slab Serif
Mathematical
Cyrillic Small Caps & Old Style
Monospaced Figures
Decorative & Display
OpenType Pro Swash
Didone (Modern)
Opticals Symbol
Expert Collection Ornamentals
Transitional
Garalde Oldstyle Phonetic
Venetian Oldstyle
Glyphic
Typography
& the Web
Operating System
Defaults
WINDOWS WINDOWS WINDOWS WINDOWS WINDOWS WINDOWS
95 98 2000 XP Vista 7
Fonts New Fonts New Fonts New Fonts New Fonts New Fonts
Arial Abadi MT Condensed Light Comic Sans MS Estrangelo Edessa Cambria Gabriola
Arial Bold Aharoni Bold Comic Sans MS Bold Franklin Gothic Medium Calibri Segoe Print
Arial Bold Italic Arial Black Georgia Franklin Gothic Med. Italic Candara Segoe Print Bold
Georgia Bold Gautami Segoe Script
Arial Italic Book Antiqua Consolas
Georgia Bold Italic
Courier Calisto MT Kartika Constantina Segoe Script Bold
Georgia Italic
Courier New Century Gothic Impact Latha Corbel Segoe UI Light
Courier New Bold Century Gothic Bold Mangal Lucida Console Nyala Segoe UI Semibold
Courier New Bold Italic Century Gothic Bold Italic Microsot Sans Serif Lucida Sans Demibold Segoe UI Segoe UI Symbol
Courier New Italic Century Gothic Italic Palatino Linotype Lucida Sans Demibold Italic
Modern Comic San MS Palatino Linotype Bold Lucida Sans Unicode
MS Sans Serif Comic San MS Bold Palatino Linotype Bld Italic Modern
MS Serif Copperplate Gothic Bold Palatino Linotype Italic Mv Boli
Roman Plantagenet Cherokee
Small Fonts Copperplate Gothic Light
Script
Symbol Impact Raavi NOTE:
Trebuchet MS
Times New Roman Lucida Console Script he new Vista fonts are the
Trebuchet MS Bold
Times New Roman Bold Lucida Handwriting Italic Shruti newer cleartype format
Trebuchet MS Bold Italic
Times New Roman Italic Lucida Sans Italic Sylfaen designed for the new Vista
Trebuchet MS Italic
display technology. Microsot
Times New Roman Bld Italic Lucida Sans Unicode Wingdings Tunga
designed these to become
Wingdings Marlett Vrinda
replacements for:
Matisse ITC WST_Czec
News Gothic MT WST_Engl Cambria = Georga and
News Gothic MT Bold WST_Fren Times New Roman
News Gothic MT Italic WST_Germ Calibri = Arial
OCR A Extended WST_Ital
Candara = Trebuchet MS and
Tahoma WST_Span
Helvetica
Tahoma Bold WST_Swed
Tempus Sans ITC Consolas = Lucidia Console
Verdana and Courier New
Verdana Bold Constantia = Georga and
Verdana Bold Italic Palatino
Verdana Italic
Webdings Corbel = Verdana
Provided by:
Westminster
XP 133
Vista 191
7 235
8 278
10.5 Leopard 160
10.6 Snow Leopard 248
10.7 Lion 225
10.8 Mountain Lion 242
10.9 Mavericks 247
iPhone iPad
3 44 —
4 41 67
5 57 57
6 61 61
7 71 71
1-3 3
4 6
7 25
8 37
Microsoft’s
Core Fonts
for the Web
Not included in Windows
since Windows ME in
2000
Wide Narrow
Verdana Futura
Trebuchet MS Helvetica
Arial
Avenir
Serif
Wide Narrow
Palatino Baskerville
Superclarendon Cochin
Monospace
Wide Narrow
American
Typewriter
Text
Properties
White Space
white-space
Is whitespace collapsed?
column-count
» Specifies ideal number of columns for content
» If column-width is set, becomes maximum number of
columns
columns
Shorthand for column-width & column-count
column-gap
Specifies size of the gap between columns
column-rule
Specifies a straight line (rule) to be drawn between
each column
Shorthand for
» column-rule-width (<length> data type or thin,
medium, or thick)
» column-rule-style
» column-rule-color
column-span
Allows an element (like <h2>) to span across all
columns
Values:
» all: spans all columns
» none: does not span multiple columns (default)
Punctuation
Generated Content
quotes
Specifies how rendering engines should render
quotation marks
R. Scott Granneman
Jans Carton
Attribution. You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so
in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. Give credit to:
Share Alike. If you remix, transform, or build upon the material, you must distribute your contributions under the same
license as the original.
No additional restrictions. You may not apply legal terms or technological measures that legally restrict others from doing
anything the license permits.