|
| 1 | +# Typography |
| 2 | + |
| 3 | +Typography in CSS is an essential aspect of web design, as it greatly influences the readability, aesthetics, and overall user experience of a website. Here are the key concepts and properties related to typography in CSS: |
| 4 | + |
| 5 | +**1. Font Family** |
| 6 | + |
| 7 | +The `font-family` property specifies the typeface for the text. It can include a specific font name and one or more generic font families. |
| 8 | + |
| 9 | +```css |
| 10 | +body { |
| 11 | + font-family: 'Arial', sans-serif; |
| 12 | +} |
| 13 | +``` |
| 14 | + |
| 15 | +**2. Font Size** |
| 16 | + |
| 17 | +The font-size property controls the size of the text. It can be set in various units like pixels (`px`), em units (`em`), rem units (`rem`), percentages (`%`), and more. |
| 18 | + |
| 19 | +```css |
| 20 | +p { |
| 21 | + font-size: 16px; |
| 22 | +} |
| 23 | + |
| 24 | +h1 { |
| 25 | + font-size: 2em; /* 2 times the current font size */ |
| 26 | +} |
| 27 | +``` |
| 28 | +You can check the relation between units |
| 29 | + |
| 30 | +| Unit | Description | |
| 31 | +| :--------: | :--------: | |
| 32 | +| `em` | Calculated relative to the current font size. For example, 2em indicates 2 times larger size than current element's font size. | |
| 33 | +| `px` | `px` stands for "pixels." It's a unit of measurement commonly used in digital design and web development to define the size of elements on a screen. | |
| 34 | +| `%` | Percentage (`%`) is a relative unit of measurement that expresses a value as a fraction of the parent element's size or the viewport's dimensions.For example, 50% of the width of the container. | |
| 35 | +| `rem` | Relative to font size of the root-element. | |
| 36 | +| `vw` | Viewport width (`vw`) is a relative unit of measurement that expresses a value as a fraction of the width of the browser viewport. `1vw` is equal to 1% of the width of the viewport. | |
| 37 | +| `vh` | Viewport height (`vh`) is a relative unit of measurement that expresses a value as a fraction of the height of the browser viewport. `1vh` is equal to 1% of the height of the viewport. | |
| 38 | + |
| 39 | + |
| 40 | +**3. Font Weight** |
| 41 | + |
| 42 | +The `font-weight` property defines the thickness of the characters. Common values include `normal`, `bold`, `bolder`, `lighter`, or numerical values ranging from 100 to 900. |
| 43 | + |
| 44 | +```css |
| 45 | +strong { |
| 46 | + font-weight: bold; |
| 47 | +} |
| 48 | + |
| 49 | +p.light { |
| 50 | + font-weight: 300; |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +**4. Font Style** |
| 55 | + |
| 56 | +The `font-style` property allows you to italicize the text. |
| 57 | + |
| 58 | +```css |
| 59 | +em { |
| 60 | + font-style: italic; |
| 61 | +} |
| 62 | + |
| 63 | +p.oblique { |
| 64 | + font-style: oblique; |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +**5. Font Variant** |
| 69 | + |
| 70 | +The `font-variant` property is used for small-caps and other typographic features. |
| 71 | + |
| 72 | +```css |
| 73 | +p { |
| 74 | + font-variant: small-caps; |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +**6. Text Transform** |
| 79 | + |
| 80 | +The `text-transform` property changes the case of the text. |
| 81 | + |
| 82 | +```css |
| 83 | +h1 { |
| 84 | + text-transform: uppercase; |
| 85 | +} |
| 86 | + |
| 87 | +p { |
| 88 | + text-transform: capitalize; |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +**7. Text Alignment** |
| 93 | + |
| 94 | +The `text-align` property sets the horizontal alignment of the text. |
| 95 | + |
| 96 | +```css |
| 97 | +div { |
| 98 | + text-align: center; |
| 99 | +} |
| 100 | + |
| 101 | +p { |
| 102 | + text-align: justify; |
| 103 | +} |
| 104 | +``` |
| 105 | + |
| 106 | +**8. Text Decoration** |
| 107 | + |
| 108 | +The `text-decoration` property adds decorations to the text, such as underlines, overlines, and line-throughs. |
| 109 | + |
| 110 | +```css |
| 111 | +a { |
| 112 | + text-decoration: none; /* Removes underline from links */ |
| 113 | +} |
| 114 | + |
| 115 | +del { |
| 116 | + text-decoration: line-through; |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +**9. Text Shadow** |
| 121 | + |
| 122 | +The `text-shadow` property adds a shadow effect to the text. |
| 123 | + |
| 124 | +```css |
| 125 | +h1 { |
| 126 | + text-shadow: 2px 2px 5px gray; |
| 127 | +} |
| 128 | +``` |
0 commit comments