Colors, Fonts, and Text Styling in CSS
When building a website, layout is important — but colors, fonts, and text styling are what give your site personality and readability. CSS allows you to control how text looks and feels, making your web pages more attractive and user-friendly.
In this blog, we’ll cover the basics of colors, fonts, and text styling in CSS, with simple examples that beginners can easily understand.
Using Colors in CSS
Colors in CSS can be applied to:
-
Text
-
Backgrounds
-
Borders
-
Links and buttons
1. Text Color
You can change text color using the color property.
2. Background Color
To change the background color of an element:
Ways to Define Colors in CSS
CSS supports multiple color formats:
-
Color names –
red,blue,green -
HEX values –
#ff5733 -
RGB –
rgb(255, 87, 51) -
RGBA –
rgba(255, 87, 51, 0.5)(adds transparency)
Beginners often start with color names and HEX values.
Fonts in CSS
Fonts affect how readable and professional your website looks.
1. Font Family
The font-family property defines which font is used.
Always include a fallback font, in case the first one isn’t available.
2. Font Size
Controls the size of text.
Common units:
-
px(pixels) -
em -
rem -
%
3. Font Weight
Controls how bold the text is.
Values can be:
-
normal -
bold -
lighter -
Numbers like
400,700
Text Styling in CSS
CSS provides many properties to style text.
1. Text Alignment
Aligns text horizontally.
Options include:
-
left -
right -
center -
justify
2. Text Decoration
Used for underlines and line effects.
Common values:
-
underline -
overline -
line-through -
none
3. Text Transform
Changes text case.
Options:
-
uppercase -
lowercase -
capitalize
4. Line Height
Controls spacing between lines.
Good line spacing improves readability.
5. Letter Spacing
Controls space between letters.
Simple Example: Combining Everything
This small CSS snippet already creates a clean and readable design.
Why Text Styling Matters
Good text styling:
-
Improves readability
-
Makes content more engaging
-
Builds trust with users
-
Helps users stay longer on your website
Poor font or color choices can make even good content hard to read.
Conclusion
Colors, fonts, and text styling are the foundation of good web design. With just a few CSS properties, you can transform plain HTML into a visually appealing website.
As a beginner, focus on simplicity and readability first. With practice, you’ll learn how to create beautiful designs using CSS.
Comments
Post a Comment