Web typography cheat sheet
Metrics
-
1rem,100%,16pxBody copy size — should never be smaller.
110%for large screens.120%for extra large screens.
-
1.3–1.5Body line-height — looser on the web.
1.3for small screens.1.4for medium screens.1.5for large screens.
-
30em–40emBody maximum line-length.
Shorter on small screens is okay.
Units
-
remBased on the font-size set in the
htmlelement.1.5remis 1.5 × thehtmlelement’s font size.
-
emBased on the font-size of the parent (or current element).
1emis 1 × the parent element’s size.0.5emis 0.5 × the parent element’s size.
-
%Percentage
A percentage of the font-size of the parent element.
80%is to 80% the size of the parent element.
-
vhViewport height
Allows you to change the type size based on the height of the window.
-
vwViewport width
Allows you to change the type size based on the width of the window.
-
pxCSS pixels—different sizes for every device.
16pxis exactly 16 pixels in all situations.Avoid using pixels for font sizes unless absolutely necessary.
Properties
-
colorThe colour of the text.
color: red;
-
font-familyChange the typeface of the text.
Put quotes around typefaces with spaces in their names.
Always provide a fallback typeface.
Web safe fonts: Georgia, Arial, Verdana, Times, Comic Sans, Courier.
font-family: "Open Sans", sans-serif;
-
font-sizeChange the size of the text.
Prefer
remoremunits.font-size: 1.5rem;
-
font-weightChange the thickness of the text.
bold,normal, number:400,700, etc.font-weight: bold;
-
font-styleChange the slanting of the text.
italic,normalfont-style: italic;
-
line-heightAdjust the space a line takes up, similar to leading.
Set in a number, a multiplier of the font size.
line-height: 1.4;
-
text-alignAdjust the position of the text within its parent.
left,right,center,justifytext-align: center;
-
text-decorationAdd or remove lines on the text.
none,underline,line-through,overlinetext-decoration: none;
-
text-transformChange the capitalization of the text.
uppercase,lowercase,capitalizetext-transform: uppercase;
-
text-indentIndent the first line of text.
Set the number in ems.
text-indent: .8em;
-
text-shadowAdd a drop shadow to the text.
Needs four properties: horizontal offset, vertical offset, blur radius, colour.
Use a comma after the colour to add more than one shadow.
text-shadow: 2px 2px 5px rgba(0,0,0,.5);
-
text-overflowDetermine what happens to the text if it’s too wide for its box.
Often requires
overflow: hidden;to be used.ellipsis,clip, custom:"."text-overflow: ellipsis;
-
list-style-typeControl the style of bullets on a list.
none,circle,disc,square,decimal,lower-alpha,lower-roman,lower-greeklist-style-type: square;
-
fontShorthand property for specifying lots of font details.
Syntax:
font: [font-style] [font-variant] font-weight font-size/line-height font-family;font: normal 100%/1.5 sans-serif;
-
letter-spacingControls the space between the different letters.
letter-spacing: .3em;
-
word-spacingControls the space between the different words.
word-spacing: 1em;
-
white-spaceControls how the text wraps.
normal,nowrap,prewhite-space: nowrap;
-
word-wrapControls whether the browser is allowed to break really long words.
normal,break-wordword-wrap: break-word;
-
::first-lineSelect the first line of text.
Good for highlighting the first line of a paragraph.
p::first-line {}
-
::first-letterSelect the first character in the text.
Good for drop caps.
p::first-letter {}
-
::selectionNot a property, but a selector.
Style an element when it has been selected and highlighted.
::selection { color: red; }
Text-flow columns
For making text flow between a few columns.
-
column-countSet to the number of columns wanted in the text block.
column-count: 2;
-
column-gapSet the amount of space between the columns.
column-gap: 1.5rem;
-
column-ruleCreate a vertical border between each column.
Exact same 3 values as a
border.column-rule: 2px solid #e2e2e2;
-
Example layout
-
Example HTML
<main class="main"> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</p> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</p> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</p> </main>
-
Column CSS properties
.main { column-count: 2; column-gap: 1.5rem; column-rule: 2px solid #e2e2e2; }
Experimental properties
These properties may not work in all browsers and may have a major performance impact.
-
hyphensControl if the text will be hyphenated.
Usually requires
text-align: justify.none,autoExample:
hyphens: auto;
-
font-kerningControl a font’s built-in kerning metrics.
none,normal,autoExample:
font-kerning: auto;
-
font-variant-ligaturesControl whether ligatures are used or not.
none,normal, specific:common-ligatures,contextual, etc.Example:
font-variant-ligatures: normal;
-
font-variant-numericEnable/disabled alternative glyphs for numbers & fractions.
normal,ordinal,slashed-zero,oldstyle-nums,tabular-nums, etc.Example:
font-variant-numeric: oldstyle-nums;
-
font-variant-capsControl whether small caps are used or not.
normal,small-capsExample:
font-variant-caps: small-caps;
-
text-renderingControls a bunch of the
font-variantproperties automatically.Has extreme performance issues.
Example:
text-rendering: optimizeLegibility;
Keyboard shortcuts
Some of these keyboard shortcuts may require the ABC Extended keyboard (or U.S. Extended).
-
“ ”Double curly quote.
“— Mac:⌥[”— Mac:⌥⇧]
-
‘ ’Single curly quote, apostrophe.
‘— Mac:⌥]’— Mac:⌥⇧]
-
« »Double guillemet.
«— Mac:⌥\»— Mac:⌥⇧\
-
‹ ›Single guillemet.
‹— Mac:⌥⇧3›— Mac:⌥⇧4
-
–En-dash.
Mac:
⌥-
-
—Em-dash.
Mac:
⌥⇧-
-
•Bullet.
Mac:
⌥8
-
·Middle dot.
Mac:
⌥⇧9
-
°Degree.
Mac:
⌥⇧8
-
…Ellipsis.
Mac:
⌥;
-
№Numero.
Mac:
⌥⇧;
-
¶Pilcrow.
Mac:
⌥7;
-
‡Double dagger.
Mac:
⌥⇧7;
-
¢Cents.
Mac:
⌥4
-
§Section.
Mac:
⌥5
-
©Copyright.
Mac:
⌥G
