Text and Font Styling in CSS
🎨 Text and Font Styling in CSS
CSS provides powerful tools to style text and
fonts, allowing developers to control the appearance and readability of web
content. Below are the most common properties used for styling text and fonts.
✅ 1. color
Defines the color of the text.
p {
color:
#333333;
}
✅ 2. font-family
Sets the typeface for the text.
p {
font-family: Arial, Helvetica, sans-serif;
}
Tip:
Always include fallback fonts in case the primary one isn’t available.
✅ 3. font-size
Controls the size of the text.
p {
font-size:
16px;
}
Common
Units:
·
px
(pixels)
·
em
(relative to
parent)
·
rem
(relative to
root)
·
%
(relative to
parent)
✅ 4. font-weight
Defines the thickness of the text.
p {
font-weight: bold;
}
Values:
·
normal
·
bold
·
lighter
·
Numeric: 100
to
900
✅ 5. font-style
Makes text italic or oblique.
p {
font-style: italic;
}
✅ 6. text-align
Aligns the text inside its container.
p {
text-align: center;
}
Values:
·
left
·
right
·
center
·
justify
✅ 7. text-decoration
Adds decoration to text like underline,
line-through, etc.
a {
text-decoration: none;
}
Values:
·
none
·
underline
·
line-through
·
overline
✅ 8. line-height
Sets the vertical spacing between lines of
text.
p {
line-height:
1.5;
}
✅ 9. letter-spacing
Controls space between characters.
p {
letter-spacing:
1px;
}
✅ 10. text-transform
Changes the case of text.
h1 {
text-transform: uppercase;
}
Values:
·
uppercase
·
lowercase
·
capitalize