CSS Styling: Beyond the Basics
Take your CSS skills further by mastering text styling, the box model, backgrounds, and display properties to create visually appealing websites.
If CSS Basics introduced the fundamentals, this lesson is where we start making interfaces look polished. You'll learn how to style text, manage spacing, customize backgrounds, and control how elements behave on the page.
Text Styling
Text Styling Properties
| Property | Function |
|---|---|
color | Text color |
font-size | Font size (px, rem, %, etc) |
font-family | Font type |
font-weight | Font thickness (normal, bold, 500, etc) |
text-align | Alignment (left, right, center, justify) |
line-height | Line spacing |
letter-spacing | Letter spacing |
text-transform | Change case (uppercase/lowercase/capitalize) |
Example
p {
font-family: 'Poppins', sans-serif;
font-size: 18px;
color: #333;
text-align: justify;
line-height: 1.8;
text-transform: capitalize;
}Your paragraphs won't just be readable, they'll look good too.
Box Model: Understanding HTML's Box World
"All HTML elements are essentially boxes. CSS helps you arrange these boxes like building a layout system."
Box Model consists of
Margin: outer space
Border: edge line
Padding: inner space
Content: actual contentExplanation
- Content: main content (text/image)
- Padding: space between content and border
- Border: element edge line
- Margin: space between elements
Styling Example
.box {
width: 300px;
height: 200px;
padding: 20px;
margin: 40px auto;
border: 2px solid #ff4d4d;
background-color: #fff0f5;
}Padding gives content breathing room, while margin creates space between elements.
Width & Height
Important properties
width→ element widthheight→ element height
Units you can use:
px→ fixed%→ relative to parentvw/vh→ relative to screen size
.card {
width: 80%;
height: auto;
}Background Styling
Commonly used properties
| Property | Function |
|---|---|
background-color | Background color |
background-image | Background image |
background-size | Image size (cover, contain) |
background-repeat | Repeat image or not |
background-position | Image position (center, top, etc) |
body {
background-color: #f0f0f0;
background-image: url('bg.png');
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}Border & Radius
Border properties
.box {
border: 3px dashed #ff69b4;
border-radius: 12px;
}border: edge line (solid, dashed, dotted)border-radius: makes corners rounded
Perfect for styling cards so they feel more modern and approachable.
Box Shadow
Glow effects, depth, and elevation can all be created using box-shadow.
.card {
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.2);
}General format:
box-shadow: x-offset y-offset blur color;Block vs Inline vs Inline-block
Element display types
| Type | Effect |
|---|---|
block | Takes full width (like div and p) |
inline | Only as wide as content (like span and a) |
inline-block | Can set width/height but stays inline |
Example
span {
display: inline-block;
width: 100px;
height: 100px;
}