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.

p { color: blue; }

2. Background Color

To change the background color of an element:

div { background-color: lightgray; }

Ways to Define Colors in CSS

CSS supports multiple color formats:

  • Color namesred, blue, green

  • HEX values#ff5733

  • RGBrgb(255, 87, 51)

  • RGBArgba(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.

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

Always include a fallback font, in case the first one isn’t available.


2. Font Size

Controls the size of text.

h1 { font-size: 32px; } p { font-size: 16px; }

Common units:

  • px (pixels)

  • em

  • rem

  • %


3. Font Weight

Controls how bold the text is.

p { font-weight: bold; }

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.

h1 { text-align: center; }

Options include:

  • left

  • right

  • center

  • justify


2. Text Decoration

Used for underlines and line effects.

a { text-decoration: none; }

Common values:

  • underline

  • overline

  • line-through

  • none


3. Text Transform

Changes text case.

p { text-transform: uppercase; }

Options:

  • uppercase

  • lowercase

  • capitalize


4. Line Height

Controls spacing between lines.

p { line-height: 1.6; }

Good line spacing improves readability.


5. Letter Spacing

Controls space between letters.

h1 { letter-spacing: 2px; }

Simple Example: Combining Everything

body { background-color: #f5f5f5; font-family: Verdana, sans-serif; } h1 { color: #333; text-align: center; } p { color: #555; font-size: 16px; line-height: 1.6; }

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

Popular posts from this blog

Numbers & Numeric Operations in C++: Data Types & cmath Functions

Introduction to C++: Your First Program & Hello World

Intro to C++ for Beginners

User Input in C++: Reading Data from Keyboard with cin & getline()

Mad Libs Game in C++: Build Your First Interactive Program

Strings in C++: Basics, Methods & Examples

Variables & Data Types in C++: Basics with Examples

Printing Patterns in C++: Shape Output with Loops & Logic

Return Statement in C++: Syntax, Purpose & Examples

Functions in C++: Syntax, Use & Examples