CSS Typography Cheatsheet with Examples

css /* CSS Typography Cheatsheet */ /* 1. Font Family */ /* Sets the font family for text */ body { font-family: 'Arial', sans-serif; /* Fallback to sans-serif if Arial is not available */ } /* 2. Font Size */ /* Sets the size of the font */ h1 { font-size: 2.5rem; /* Relative to the root element */ } p { font-size: 16px; /* Absolute size in pixels */ } /* 3. Font Weight */ /* Sets the thickness of the font */ .bold-text { font-weight: bold; /* Keyword value */ } .light-text { font-weight: 300; /* Numeric value (100-900) */ } /* 4. Font Style */ /* Sets the style of the font */ .italic-text { font-style: italic; /* Italic text */ } .normal-text { font-style: normal; /* Normal text */ } /* 5. Line Height */ /* Sets the height of a line of text */ p { line-height: 1.6; /* Unitless value (relative to font size) */ } /* 6. Text Align */ /* Aligns the text horizontally */ .center-text { text-align: center; /* Centers text */ } .right-text { text-align: right; /* Aligns text to the right */ } .left-text { text-align: left; /* Aligns text to the left */ } .justify-text { text-align: justify; /* Justifies text */ } /* 7. Text Decoration */ /* Adds decoration to text */ .underline-text { text-decoration: underline; /* Underlines text */ } .line-through-text { text-decoration: line-through; /* Strikes through text */ } .no-decoration { text-decoration: none; /* Removes any text decoration */ } /* 8. Text Transform */ /* Transforms the case of text */ .uppercase-text { text-transform: uppercase; /* Converts text to uppercase */ } .lowercase-text { text-transform: lowercase; /* Converts text to lowercase */ } .capitalize-text { text-transform: capitalize; /* Capitalizes the first letter of each word */ } /* 9. Letter Spacing */ /* Sets the spacing between characters */ .wide-spacing { letter-spacing: 3px; /* Increases space between characters */ } .tight-spacing { letter-spacing: -1px; /* Decreases space between characters */ } /* 10. Word Spacing */ /* Sets the spacing between words */ .wide-word-spacing { word-spacing: 10px; /* Increases space between words */ } .tight-word-spacing { word-spacing: -2px; /* Decreases space between words */ } /* 11. Text Shadow */ /* Adds shadow to text */ .shadow-text { text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); /* horizontal vertical blur color */ } /* 12. Font Variant */ /* Sets small-caps or normal font variant */ .small-caps-text { font-variant: small-caps; /* Displays text in small caps */ } /* 13. White Space */ /* Controls how white space inside an element is handled */ .pre-wrap-text { white-space: pre-wrap; /* Preserves whitespace and wraps text */ } .nowrap-text { white-space: nowrap; /* Prevents text from wrapping */ } /* 14. Color */ /* Sets the color of the text */ .red-text { color: #ff0000; /* Hexadecimal color */ } .blue-text { color: rgb(0, 0, 255); /* RGB color */ } .green-text { color: rgba(0, 255, 0, 0.5); /* RGBA color with transparency */ } /* 15. Font Stretch */ /* Sets the width of the font */ .condensed-text { font-stretch: condensed; /* Condensed font */ } .expanded-text { font-stretch: expanded; /* Expanded font */ } /* 16. Text Overflow */ /* Controls how overflowed content is displayed */ .ellipsis-text { white-space: nowrap; /* Prevents wrapping */ overflow: hidden; /* Hides overflow */ text-overflow: ellipsis; /* Adds ellipsis to overflowed text */ } /* 17. Vertical Align */ /* Aligns text vertically within an element */ .superscript { vertical-align: super; /* Aligns text as superscript */ } .subscript { vertical-align: sub; /* Aligns text as subscript */ } /* 18. Direction */ /* Sets the text direction */ .rtl-text { direction: rtl; /* Right-to-left text direction */ } .ltr-text { direction: ltr; /* Left-to-right text direction */ } /* 19. Writing Mode */ /* Sets the writing mode */ .vertical-text { writing-mode: vertical-rl; /* Vertical text, right-to-left */ } .horizontal-text { writing-mode: horizontal-tb; /* Horizontal text, top-to-bottom */ } /* 20. Font Kerning */ /* Controls the spacing between characters */ .kerning-on { font-kerning: normal; /* Enables kerning */ } .kerning-off { font-kerning: none; /* Disables kerning */ } /* 21. Font Feature Settings */ /* Enables or disables OpenType font features */ .ligatures-on { font-feature-settings: "liga" 1; /* Enables ligatures */ } .ligatures-off { font-feature-settings: "liga" 0; /* Disables ligatures */ } /* 22. Text Indent */ /* Indents the first line of text */ .indented-text { text-indent: 50px; /* Indents the first line by 50px */ } /* 23. Text Orientation */ /* Sets the orientation of text */ .upright-text { text-orientation: upright; /* Keeps text upright */ } .sideways-text { text-orientation: sideways; /* Rotates text sideways */ } /* 24. Text Rendering *

Mar 12, 2025 - 16:47
 0
CSS Typography Cheatsheet with Examples

css
/* CSS Typography Cheatsheet */

/* 1. Font Family */
/* Sets the font family for text */
body {
    font-family: 'Arial', sans-serif; /* Fallback to sans-serif if Arial is not available */
}

/* 2. Font Size */
/* Sets the size of the font */
h1 {
    font-size: 2.5rem; /* Relative to the root element */
}

p {
    font-size: 16px; /* Absolute size in pixels */
}

/* 3. Font Weight */
/* Sets the thickness of the font */
.bold-text {
    font-weight: bold; /* Keyword value */
}

.light-text {
    font-weight: 300; /* Numeric value (100-900) */
}

/* 4. Font Style */
/* Sets the style of the font */
.italic-text {
    font-style: italic; /* Italic text */
}

.normal-text {
    font-style: normal; /* Normal text */
}

/* 5. Line Height */
/* Sets the height of a line of text */
p {
    line-height: 1.6; /* Unitless value (relative to font size) */
}

/* 6. Text Align */
/* Aligns the text horizontally */
.center-text {
    text-align: center; /* Centers text */
}

.right-text {
    text-align: right; /* Aligns text to the right */
}

.left-text {
    text-align: left; /* Aligns text to the left */
}

.justify-text {
    text-align: justify; /* Justifies text */
}

/* 7. Text Decoration */
/* Adds decoration to text */
.underline-text {
    text-decoration: underline; /* Underlines text */
}

.line-through-text {
    text-decoration: line-through; /* Strikes through text */
}

.no-decoration {
    text-decoration: none; /* Removes any text decoration */
}

/* 8. Text Transform */
/* Transforms the case of text */
.uppercase-text {
    text-transform: uppercase; /* Converts text to uppercase */
}

.lowercase-text {
    text-transform: lowercase; /* Converts text to lowercase */
}

.capitalize-text {
    text-transform: capitalize; /* Capitalizes the first letter of each word */
}

/* 9. Letter Spacing */
/* Sets the spacing between characters */
.wide-spacing {
    letter-spacing: 3px; /* Increases space between characters */
}

.tight-spacing {
    letter-spacing: -1px; /* Decreases space between characters */
}

/* 10. Word Spacing */
/* Sets the spacing between words */
.wide-word-spacing {
    word-spacing: 10px; /* Increases space between words */
}

.tight-word-spacing {
    word-spacing: -2px; /* Decreases space between words */
}

/* 11. Text Shadow */
/* Adds shadow to text */
.shadow-text {
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); /* horizontal vertical blur color */
}

/* 12. Font Variant */
/* Sets small-caps or normal font variant */
.small-caps-text {
    font-variant: small-caps; /* Displays text in small caps */
}

/* 13. White Space */
/* Controls how white space inside an element is handled */
.pre-wrap-text {
    white-space: pre-wrap; /* Preserves whitespace and wraps text */
}

.nowrap-text {
    white-space: nowrap; /* Prevents text from wrapping */
}

/* 14. Color */
/* Sets the color of the text */
.red-text {
    color: #ff0000; /* Hexadecimal color */
}

.blue-text {
    color: rgb(0, 0, 255); /* RGB color */
}

.green-text {
    color: rgba(0, 255, 0, 0.5); /* RGBA color with transparency */
}

/* 15. Font Stretch */
/* Sets the width of the font */
.condensed-text {
    font-stretch: condensed; /* Condensed font */
}

.expanded-text {
    font-stretch: expanded; /* Expanded font */
}

/* 16. Text Overflow */
/* Controls how overflowed content is displayed */
.ellipsis-text {
    white-space: nowrap; /* Prevents wrapping */
    overflow: hidden; /* Hides overflow */
    text-overflow: ellipsis; /* Adds ellipsis to overflowed text */
}

/* 17. Vertical Align */
/* Aligns text vertically within an element */
.superscript {
    vertical-align: super; /* Aligns text as superscript */
}

.subscript {
    vertical-align: sub; /* Aligns text as subscript */
}

/* 18. Direction */
/* Sets the text direction */
.rtl-text {
    direction: rtl; /* Right-to-left text direction */
}

.ltr-text {
    direction: ltr; /* Left-to-right text direction */
}

/* 19. Writing Mode */
/* Sets the writing mode */
.vertical-text {
    writing-mode: vertical-rl; /* Vertical text, right-to-left */
}

.horizontal-text {
    writing-mode: horizontal-tb; /* Horizontal text, top-to-bottom */
}

/* 20. Font Kerning */
/* Controls the spacing between characters */
.kerning-on {
    font-kerning: normal; /* Enables kerning */
}

.kerning-off {
    font-kerning: none; /* Disables kerning */
}

/* 21. Font Feature Settings */
/* Enables or disables OpenType font features */
.ligatures-on {
    font-feature-settings: "liga" 1; /* Enables ligatures */
}

.ligatures-off {
    font-feature-settings: "liga" 0; /* Disables ligatures */
}

/* 22. Text Indent */
/* Indents the first line of text */
.indented-text {
    text-indent: 50px; /* Indents the first line by 50px */
}

/* 23. Text Orientation */
/* Sets the orientation of text */
.upright-text {
    text-orientation: upright; /* Keeps text upright */
}

.sideways-text {
    text-orientation: sideways; /* Rotates text sideways */
}

/* 24. Text Rendering */
/* Optimizes text rendering */
.optimize-legibility {
    text-rendering: optimizeLegibility; /* Improves legibility */
}

.optimize-speed {
    text-rendering: optimizeSpeed; /* Prioritizes rendering speed */
}

/* 25. Font Size Adjust */
/* Adjusts the font size based on the height of lowercase letters */
.adjusted-font {
    font-size-adjust: 0.58; /* Adjusts font size */
}

/* 26. Hyphens */
/* Controls hyphenation of text */
.hyphens-auto {
    hyphens: auto; /* Automatically hyphenates text */
}

.hyphens-none {
    hyphens: none; /* Disables hyphenation */
}

/* 27. Text Justify */
/* Controls the justification method */
.justify-inter-word {
    text-justify: inter-word; /* Justifies text by adjusting word spacing */
}

.justify-inter-character {
    text-justify: inter-character; /* Justifies text by adjusting character spacing */
}

/* 28. Text Underline Position */
/* Sets the position of the underline */
.underline-below {
    text-underline-position: under; /* Places underline below the text */
}

.underline-above {
    text-underline-position: above; /* Places underline above the text */
}

/* 29. Text Combine Upright */
/* Combines characters in vertical writing mode */
.combine-upright {
    text-combine-upright: all; /* Combines characters into a single space */
}

/* 30. Text Emphasis */
/* Adds emphasis marks to text */
.emphasis-dot {
    text-emphasis: dot; /* Adds a dot as emphasis */
}

.emphasis-circle {
    text-emphasis: circle red; /* Adds a red circle as emphasis */
}

/* 31. Text Orientation */
/* Sets the orientation of text in vertical writing mode */
.mixed-orientation {
    text-orientation: mixed; /* Mixed orientation for vertical text */
}

/* 32. Text Overflow */
/* Controls how overflowed content is displayed */
.clip-text {
    white-space: nowrap; /* Prevents wrapping */
    overflow: hidden; /* Hides overflow */
    text-overflow: clip; /* Clips overflowed text */
}

/* 33. Text Shadow */
/* Adds multiple shadows to text */
.multiple-shadows {
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5), -2px -2px 4px rgba(255, 255, 255, 0.5); /* Multiple shadows */
}

/* 34. Text Stroke */
/* Adds a stroke to text */
.stroke-text {
    -webkit-text-stroke: 2px black; /* Adds a black stroke to text */
}

/* 35. Text Fill Color */
/* Sets the fill color of text */
.fill-text {
    -webkit-text-fill-color: transparent; /* Makes text transparent */
    background: linear-gradient(to right, red, blue); /* Adds a gradient background */
    -webkit-background-clip: text; /* Clips background to text */
}

/* 36. Text Decoration Thickness */
/* Sets the thickness of text decoration */
.thick-underline {
    text-decoration-thickness: 3px; /* Sets underline thickness */
}

/* 37. Text Decoration Style */
/* Sets the style of text decoration */
.dashed-underline {
    text-decoration-style: dashed; /* Dashed underline */
}

/* 38. Text Decoration Color */
/* Sets the color of text decoration */
.colored-underline {
    text-decoration-color: blue; /* Blue underline */
}

/* 39. Text Decoration Line */
/* Sets the line type of text decoration */
.double-underline {
    text-decoration-line: underline; /* Double underline */
}

/* 40. Text Decoration Skip */
/* Controls which parts of the text are skipped by decoration */
.skip-underline {
    text-decoration-skip: spaces; /* Skips spaces in underline */
}

/* 41. Text Decoration Skip Ink */
/* Controls how text decoration interacts with glyphs */
.skip-ink {
    text-decoration-skip-ink: auto; /* Skips ink for better readability */
}

/* 42. Text Underline Offset */
/* Sets the offset of the underline */
.underline-offset {
    text-underline-offset: 5px; /* Offsets underline by 5px */
}

/* 43. Text Wrap */
/* Controls how text wraps */
.wrap-text {
    text-wrap: wrap; /* Wraps text */
}

.nowrap-text {
    text-wrap: nowrap; /* Prevents text from wrapping */
}

/* 44. Text Overflow */
/* Controls how overflowed content is displayed */
.overflow-ellipsis {
    white-space: nowrap; /* Prevents wrapping */
    overflow: hidden; /* Hides overflow */
    text-overflow: ellipsis; /* Adds ellipsis to overflowed text */
}

/* 45. Text Align Last */
/* Aligns the last line of text */
.align-last-center {
    text-align-last: center; /* Centers the last line */
}

/* 46. Text Justify */
/* Controls the justification method */
.justify-all {
    text-justify: distribute; /* Distributes text evenly */
}

/* 47. Text Orientation */
/* Sets the orientation of text in vertical writing mode */
.upright-text {
    text-orientation: upright; /* Keeps text upright */
}

/* 48. Text Rendering */
/* Optimizes text rendering */
.optimize-legibility {
    text-rendering: optimizeLegibility; /* Improves legibility */
}

/* 49. Text Size Adjust */
/* Adjusts the font size based on the height of lowercase letters */
.size-adjust {
    text-size-adjust: 100%; /* Adjusts font size */
}

/* 50. Text Transform */
/* Transforms the case of text */
.capitalize-text {
    text-transform: capitalize; /* Capitalizes the first letter of each word */
}

/* 51. Text Underline Position */
/* Sets the position of the underline */
.underline-below {
    text-underline-position: under; /* Places underline below the text */
}

/* 52. Text Wrap */
/* Controls how text wraps */
.wrap-text {
    text-wrap: wrap; /* Wraps text */
}

/* 53. Text Overflow */
/* Controls how overflowed content is displayed */
.overflow-ellipsis {
    white-space: nowrap; /* Prevents wrapping */
    overflow: hidden; /* Hides overflow */
    text-overflow: ellipsis; /* Adds ellipsis to overflowed text */
}

/* 54. Text Align Last */
/* Aligns the last line of text */
.align-last-center {
    text-align-last: center; /* Centers the last line */
}

/* 55. Text Justify */
/* Controls the justification method */
.justify-all {
    text-justify: distribute; /* Distributes text evenly */
}

/* 56. Text Orientation */
/* Sets the orientation of text in vertical writing mode */
.upright-text {
    text-orientation: upright; /* Keeps text upright */
}

/* 57. Text Rendering */
/* Optimizes text rendering */
.optimize-legibility {
    text-rendering: optimizeLegibility; /* Improves legibility */
}

/* 58. Text Size Adjust */
/* Adjusts the font size based on the height of lowercase letters */
.size-adjust {
    text-size-adjust: 100%; /* Adjusts font size */
}

/* 59. Text Transform */
/* Transforms the case of text */
.capitalize-text {
    text-transform: capitalize; /* Capitalizes the first letter of each word */
}

/* 60. Text Underline Position */
/* Sets the position of the underline */
.underline-below {
    text-underline-position: under; /* Places underline below the text */
}

/* 61. Text Wrap */
/* Controls how text wraps */
.wrap-text {
    text-wrap: wrap; /* Wraps text */
}

/* 62. Text Overflow */
/* Controls how overflowed content is displayed */
.overflow-ellipsis {
    white-space: nowrap; /* Prevents wrapping */
    overflow: hidden; /* Hides overflow */
    text-overflow: ellipsis; /* Adds ellipsis to overflowed text */
}

/* 63. Text Align Last */
/* Aligns the last line of text */
.align-last-center {
    text-align-last: center; /* Centers the last line */
}

/* 64. Text Justify */
/* Controls the justification method */
.justify-all {
    text-justify: distribute; /* Distributes text evenly */
}

/* 65. Text Orientation */
/* Sets the orientation of text in vertical writing mode */
.upright-text {
    text-orientation: upright; /* Keeps text upright */
}

/* 66. Text Rendering */
/* Optimizes text rendering */
.optimize-legibility {
    text-rendering: optimizeLegibility; /* Improves legibility */
}

/* 67. Text Size Adjust */
/* Adjusts the font size based on the height of lowercase letters */
.size-adjust {
    text-size-adjust: 100%; /* Adjusts font size */
}

/* 68. Text Transform */
/* Transforms the case of text */
.capitalize-text {
    text-transform: capitalize; /* Capitalizes the first letter of each word */
}

/* 69. Text Underline Position */
/* Sets the position of the underline */
.underline-below {
    text-underline-position: under; /* Places underline below the text */
}

/* 70. Text Wrap */
/* Controls how text wraps */
.wrap-text {
    text-wrap: wrap; /* Wraps text */
}

/* 71. Text Overflow */
/* Controls how overflowed content is displayed */
.overflow-ellipsis {
    white-space: nowrap; /* Prevents wrapping */
    overflow: hidden; /* Hides overflow */
    text-overflow: ellipsis; /* Adds ellipsis to overflowed text */
}

/* 72. Text Align Last */
/* Aligns the last line of text */
.align-last-center {
    text-align-last: center; /* Centers the last line */
}

/* 73. Text Justify */
/* Controls the justification method */
.justify-all {
    text-justify: distribute; /* Distributes text evenly */
}

/* 74. Text Orientation */
/* Sets the orientation of text in vertical writing mode */
.upright-text {
    text-orientation: upright; /* Keeps text upright */
}

/* 75. Text Rendering */
/* Optimizes text rendering */
.optimize-legibility {
    text-rendering: optimizeLegibility; /* Improves legibility */
}

/* 76. Text Size Adjust */
/* Adjusts the font size based on the height of lowercase letters */
.size-adjust {
    text-size-adjust: 100%; /* Adjusts font size */
}

/* 77. Text Transform */
/* Transforms the case of text */
.capitalize-text {
    text-transform: capitalize; /* Capitalizes the first letter of each word */
}

/* 78. Text Underline Position */
/* Sets the position of the underline */
.underline-below {
    text-underline-position: under; /* Places underline below the text */
}

/* 79. Text Wrap */
/* Controls how text wraps */
.wrap-text {
    text-wrap: wrap; /* Wraps text */
}

/* 80. Text Overflow */
/* Controls how overflowed content is displayed */
.overflow-ellipsis {
    white-space: nowrap; /* Prevents wrapping */
    overflow: hidden; /* Hides overflow */
    text-overflow: ellipsis; /* Adds ellipsis to overflowed text */
}

/* 81. Text Align Last */
/* Aligns the last line of text */
.align-last-center {
    text-align-last: center; /* Centers the last line */
}

/* 82. Text Justify */
/* Controls the justification method */
.justify-all {
    text-justify: distribute; /* Distributes text evenly */
}

/* 83. Text Orientation */
/* Sets the orientation of text in vertical writing mode */
.upright-text {
    text-orientation: upright; /* Keeps text upright */
}

/* 84. Text Rendering */
/* Optimizes text rendering */
.optimize-legibility {
    text-rendering: optimizeLegibility; /* Improves legibility */
}

/* 85. Text Size Adjust */
/* Adjusts the font size based on the height of lowercase letters */
.size-adjust {
    text-size-adjust: 100%; /* Adjusts font size */
}

/* 86. Text Transform */
/* Transforms the case of text */
.capitalize-text {
    text-transform: capitalize; /* Capitalizes the first letter of each word */
}

/* 87. Text Underline Position */
/* Sets the position of the underline */
.underline-below {
    text-underline-position: under; /* Places underline below the text */
}

/* 88. Text Wrap */
/* Controls how text wraps */
.wrap-text {
    text-wrap: wrap; /* Wraps text */