CSS

CSS (Cascading Style Sheets) is the language that brings web pages to life with colors, layouts, and animations. It works alongside HTML to create visually stunning and responsive designs. Let's explore the power of CSS.

CSS Text

31 March 2025 | Category:

CSS provides powerful properties to style text, control alignment, spacing, decoration, and transformation. This guide covers everything you need to know about CSS text properties.


1️⃣ Basic CSS Text Properties

PropertyDescription
colorSets the text color
font-sizeDefines the text size
font-familySets the font type
font-weightMakes text bold or light
font-styleDefines text style (italic, normal, oblique)
text-alignAligns text (left, center, right, justify)
text-decorationAdds underline, overline, or strikethrough
text-transformChanges text case (uppercase, lowercase, capitalize)
letter-spacingControls space between letters
word-spacingControls space between words
line-heightAdjusts spacing between lines

2️⃣ color – Setting Text Color

Defines the color of the text using:

  • Named colors (red, blue, green)
  • Hex codes (#ff0000)
  • RGB (rgb(255, 0, 0))
  • HSL (hsl(0, 100%, 50%))

Example

p {
    color: #3498db;
}

3️⃣ font-size – Adjusting Text Size

Controls the size of the text. You can use:

  • px (pixels)
  • em (relative to parent)
  • % (relative to default size)
  • rem (relative to root element)

Example

h1 {
    font-size: 24px;
}

p {
    font-size: 1.2em;
}

📌 1em = 100% of parent font size
📌 1rem = 100% of root font size


4️⃣ font-family – Choosing Fonts

Defines the typeface of text.

Example

p {
    font-family: Arial, sans-serif;
}

📌 Always provide fallback fonts in case the main font isn’t available.

Common Font Types

Font TypeExample
SerifTimes New Roman, Georgia
Sans-serifArial, Helvetica
MonospaceCourier New, Consolas

5️⃣ font-weight – Boldness of Text

Defines how thick or thin the text appears.

ValueEffect
normalDefault weight
boldMakes text bold
lighterMakes text thinner
bolderMakes text thicker
100-900Numeric values (100 = thin, 900 = extra bold)

Example

p {
    font-weight: bold;
}

h1 {
    font-weight: 700;
}

6️⃣ font-style – Italic, Oblique or Normal

Controls the style of the text.

ValueEffect
normalDefault text style
italicSlanted text
obliqueSimilar to italic

Example

p {
    font-style: italic;
}

7️⃣ text-align – Aligning Text

Controls horizontal alignment of text.

ValueEffect
leftAligns text to the left
centerCenters the text
rightAligns text to the right
justifyStretches text to fit the width

Example

p {
    text-align: center;
}

8️⃣ text-decoration – Underline, Overline, Strike

Adds decoration to text.

ValueEffect
noneRemoves decoration
underlineAdds a line below the text
overlineAdds a line above the text
line-throughAdds a strikethrough
blink(Not supported in modern browsers)

Example

p {
    text-decoration: underline;
}

9️⃣ text-transform – Changing Case

Controls text capitalization.

ValueEffect
uppercaseConverts text to ALL CAPS
lowercaseConverts text to lowercase
capitalizeCapitalizes first letter of each word

Example

h1 {
    text-transform: uppercase;
}

🔟 letter-spacing – Adjusting Space Between Letters

Defines the spacing between characters.

ValueEffect
normalDefault spacing
2pxIncreases spacing by 2 pixels
-1pxReduces spacing by 1 pixel

Example

p {
    letter-spacing: 2px;
}

1️⃣1️⃣ word-spacing – Adjusting Space Between Words

Defines the spacing between words.

Example

p {
    word-spacing: 5px;
}

1️⃣2️⃣ line-height – Controlling Line Spacing

Defines the vertical space between lines.

ValueEffect
normalDefault spacing
1.51.5 times the font size
2emTwice the height of text

Example

p {
    line-height: 1.6;
}

🎯 Summary Cheat Sheet

PropertyEffect
colorChanges text color
font-sizeSets text size
font-familyDefines font type
font-weightControls text thickness
font-styleItalic, oblique, or normal text
text-alignAligns text left, center, or right
text-decorationAdds underline, strikethrough, or overline
text-transformChanges case (uppercase, lowercase, capitalize)
letter-spacingAdjusts space between letters
word-spacingAdjusts space between words
line-heightControls space between lines

🎨 Final Example

p {
    color: #333;
    font-size: 18px;
    font-family: "Arial", sans-serif;
    font-weight: bold;
    font-style: italic;
    text-align: center;
    text-decoration: underline;
    text-transform: uppercase;
    letter-spacing: 2px;
    word-spacing: 5px;
    line-height: 1.6;
}

🎯 Conclusion

Text styling is essential for readability & design.
Use text-align: justify; for professional layouts.
Avoid text-decoration: none; for links unless replacing it with a better UI.
Line-height improves readability on larger text blocks.