Styling Text, Colors, and Layout in CSS
When you first learn HTML, everything looks plain. Black text. White background. No personality.
That’s where CSS comes in.
CSS is what turns a basic page into something readable, beautiful, and structured. In this guide, we’ll walk through text styling, color systems, borders, layout, spacing, and how the box model works — in a simple, practical way.
Choosing the Right Fonts
Fonts matter more than most beginners think. The wrong font can make your website feel outdated or hard to read.
Traditionally, some fonts are considered “web-safe” because they are available on most systems:
-
Arial
-
Courier New
-
Georgia
-
Verdana
-
Trebuchet MS
-
Times New Roman
In CSS, we use the font-family property:
This means:
-
Try Cambria first.
-
If not available, use Times New Roman.
-
If that fails, use any default serif font.
Fonts fall into categories:
-
Serif – Letters have small strokes at the ends.
-
Sans-serif – Clean letters without strokes.
-
Monospace – Each character has equal width (great for code).
-
Cursive – Looks like handwriting.
-
Fantasy – Decorative fonts.
Using Google Fonts
If you want modern typography, use external fonts.
One popular option is Google Fonts, which offers free open-source fonts for websites.
You can also include custom fonts using @font-face:
Now your website uses your own font.
Sizing Text Properly
Text size affects readability and hierarchy.
Use the font-size property:
Common units:
-
px – Fixed size.
-
% – Relative to parent.
-
em – Relative to parent’s font size.
-
rem – Relative to root (body) font size.
For example:
This makes the heading twice the size of the body text.
Good design means creating harmony between headings and paragraph text.
Formatting Text for Emphasis
CSS gives many tools for text formatting.
Font Weight
Available values:
-
normal
-
bold
-
lighter
-
bolder
-
100–900 (400 = normal, 700 = bold)
Font Style
Values:
-
normal
-
italic
-
oblique
Text Decoration
You can underline, strike through, or decorate text.
Options:
-
underline
-
overline
-
line-through
-
none
You can also style the decoration:
This gives personality to simple text.
Improving Readability
Styling isn't only about bold and color. It’s about comfort.
Text Alignment
Options:
-
left
-
right
-
center
-
justify
Text Spacing
Spacing makes content easier to read.
-
line-height → space between lines
-
letter-spacing → space between letters
-
word-spacing → space between words
-
text-indent → indent first line
Good spacing dramatically improves readability.
Understanding Color in CSS
Color defines mood, hierarchy, and branding.
CSS supports four main ways to define color:
1. Hexadecimal
2. RGB
This means full red.
3. RGBA (with transparency)
The last value (0–1) controls opacity.
Opacity can also be applied to entire elements:
4. HSL
HSL stands for:
-
Hue
-
Saturation
-
Lightness
It gives more visual control when designing themes.
Gradients in CSS
Gradients create smooth color transitions.
Linear Gradient
Radial Gradient
You can control:
-
Direction
-
Color stops
-
Multiple colors
Gradients add depth without images.
The Border Property
Borders help separate content visually.
Border styles include:
-
solid
-
dashed
-
dotted
-
double
-
groove
-
ridge
-
inset
-
outset
You can style individual sides:
CSS Layout and the Box Model
Every HTML element is treated like a box.
Each box has:
-
Content
-
Padding
-
Border
-
Margin
Understanding this is essential for layout design.
The Display Property
Display changes how elements behave.
-
block → starts on new line
-
inline → flows within text
-
inline-block → mix of both
-
none → hides element
Height and Width
By default, elements size themselves automatically.
You can control them:
Use:
-
px
-
%
-
em
-
rem
-
auto
Padding vs Margin
Padding = space inside the box.
Margin = space outside the box.
Shorthand format:
To center content:
Element Flow and Float
By default, elements appear in order.
You can change flow using float to pull elements left or right.
This is useful for:
-
Sidebars
-
Images beside text
-
Quotes

Comments
Post a Comment