CSS Text , Font & Background Properties β A Complete Guide for Beginners and Professionals

Table of contents
- What is CSS?
- Structure of a CSS Rule
- CSS Properties and Examples
- Text and Font Properties
- CSS Background Properties
- β¨ Why Background Properties Matter
- πΉ 1. background-color Property
- πΉ 2. background-image Property
- πΉ 3. background-size Property
- πΉ 4. background-position Property
- πΉ 5. background-repeat Property
- πΉ 6. background Shorthand Property
- π οΈ Summary Table of Properties
- π‘ Pro Tips for Working Professionals
- π¦ Real-World Example: Product Promotion Banner
- π Conclusion
- π― Task Title: Create a Stylish Profile Card Web Page
- π Task Instructions:
- π» Output Example: What Students Should Create
- π Concepts Practiced
- π§ Bonus Challenge (Optional)
- β Submission Instruction (if using classroom)
- π Stay Connected

Cascading Style Sheets (CSS) is the backbone of web design, enabling developers to style and layout their HTML content. With the evolution of CSS3, developers now have access to enhanced features for animations, responsive designs, and advanced styling. In this guide, weβll cover every property in CSS and CSS3, complete with explanations, examples, and possible values for each. By the end, youβll also find a consolidated table of all CSS properties and their values for quick reference.
What is CSS?
CSS (Cascading Style Sheets) is a stylesheet language used to control the presentation of HTML elements. It allows you to apply styles such as colors, layouts, spacing, and more. CSS3, the latest version, introduced new properties like animations, transitions, and grid layouts to meet modern design needs.
Structure of a CSS Rule
A CSS rule consists of:
Selector: Identifies the HTML element(s) to style.
Declaration: Specifies the style to apply. It contains a property and a value.
Example:
selector {
property: value;
}
For example:
p {
color: blue;
font-size: 16px;
}
CSS Properties and Examples
Letβs explore CSS and CSS3 properties grouped by category:
Text and Font Properties
Text and font properties in CSS are essential for controlling the presentation of textual content on a webpage. Letβs explore these properties in greater detail with real-world practical examples to demonstrate how they work and the effects they produce.
1) color
Property
The color
property changes the color of the text.
Possible Values:
Color names: Predefined names like
red
,blue
,green
.HEX values: Color defined using hexadecimal codes like
#FF5733
.RGB values: Specify red, green, and blue components, e.g.,
rgb(255, 87, 51)
.HSL values: Specify hue, saturation, and lightness, e.g.,
hsl(9, 100%, 60%)
.
Example Code:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
h1 {
color: red; /* Using color name */
}
p.hex {
color: #3498db; /* Using HEX */
}
p.rgb {
color: rgb(46, 204, 113); /* Using RGB */
}
p.hsl {
color: hsl(210, 100%, 50%); /* Using HSL */
}
</style>
</head>
<body>
<h1>This is a red heading</h1>
<p class="hex">This is a paragraph with HEX color.</p>
<p class="rgb">This is a paragraph with RGB color.</p>
<p class="hsl">This is a paragraph with HSL color.</p>
</body>
</html>
2) font-family
Property
The font-family
property specifies the font used for the text. It can include a primary font and a fallback font.
Possible Values:
Font names like
"Arial"
,"Georgia"
.Generic font families like
sans-serif
,serif
,monospace
.
Example Code:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
p.serif {
font-family: "Times New Roman", serif; /* Serif font with fallback */
}
p.sans-serif {
font-family: Arial, sans-serif; /* Sans-serif font with fallback */
}
p.monospace {
font-family: "Courier New", monospace; /* Monospace font with fallback */
}
</style>
</head>
<body>
<p class="serif">This is text in a serif font.</p>
<p class="sans-serif">This is text in a sans-serif font.</p>
<p class="monospace">This is text in a monospace font.</p>
</body>
</html>
3) font-size
Property
The font-size
property determines the size of the text.
Possible Values:
Absolute values:
px
(pixels), e.g.,16px
.Relative values:
em
,rem
, percentages.
Example Code:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
p.px {
font-size: 16px; /* Fixed size in pixels */
}
p.em {
font-size: 1.5em; /* Relative to the parent element */
}
p.rem {
font-size: 2rem; /* Relative to the root element */
}
p.percent {
font-size: 120%; /* Relative to the parent element's size */
}
</style>
</head>
<body>
<p class="px">This text has a size of 16px.</p>
<p class="em">This text is 1.5 times the size of its parent.</p>
<p class="rem">This text is 2 times the size of the root element.</p>
<p class="percent">This text is 120% of the parent's size.</p>
</body>
</html>
4) font-style
Property
The font-style
property specifies the style of the text (e.g., normal, italic, or oblique).
Possible Values:
normal
: Default style.italic
: Italicized text.oblique
: A slanted version of the font.
Example Code:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
p.normal {
font-style: normal; /* Default text style */
}
p.italic {
font-style: italic; /* Italicized text */
}
p.oblique {
font-style: oblique; /* Slanted text */
}
</style>
</head>
<body>
<p class="normal">This text is normal.</p>
<p class="italic">This text is italic.</p>
<p class="oblique">This text is oblique.</p>
</body>
</html>
5) text-align
Property
The text-align
property aligns text horizontally.
Possible Values:
left
: Aligns text to the left.right
: Aligns text to the right.center
: Centers the text.justify
: Stretches text to align both left and right edges.
Example Code:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
p.left {
text-align: left; /* Aligns to the left */
}
p.right {
text-align: right; /* Aligns to the right */
}
p.center {
text-align: center; /* Centers the text */
}
p.justify {
text-align: justify; /* Justifies the text */
}
</style>
</head>
<body>
<p class="left">This text is aligned to the left.</p>
<p class="right">This text is aligned to the right.</p>
<p class="center">This text is centered.</p>
<p class="justify">This text is justified. It will stretch the text so that it aligns both left and right margins.</p>
</body>
</html>
6) line-height
Property
The line-height
property sets the vertical space between lines of text.
Possible Values:
Fixed values (e.g.,
20px
).Relative values (e.g.,
1.5
,2
).
Example Code:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
p.fixed {
line-height: 20px; /* Fixed space between lines */
}
p.relative {
line-height: 1.8; /* Relative multiplier for spacing */
}
</style>
</head>
<body>
<p class="fixed">This paragraph has a fixed line height of 20px. The spacing between lines is the same irrespective of the font size.</p>
<p class="relative">This paragraph has a relative line height of 1.8. The space between lines increases proportionally with the font size.</p>
</body>
</html>
CSS Background Properties
CSS background properties are used to style the background of HTML elements. You can add colors, images, gradients, and control how they look and behave inside an element.
This guide will help you understand each background property with practical, real-life examples. Itβs designed for both beginners and professionals who want clean, visual interfaces.
β¨ Why Background Properties Matter
Imagine you're building:
A banner on an e-commerce homepage
A card layout for a product
A login page with a gradient or image background
In all these cases, background properties help you design professional, modern UI layouts.
πΉ 1. background-color
Property
This sets the background color of an element.
β Values You Can Use:
Named Colors β
red
,blue
,lightgray
HEX Values β
#3498db
,#ffffff
RGB Values β
rgb(255, 0, 0)
HSL Values β
hsl(0, 100%, 50%)
β Real Example:
<style>
.section1 {
background-color: #3498db;
padding: 20px;
color: white;
}
</style>
<div class="section1">This has a HEX background color.</div>
Use Case: Highlighting sections or cards in a UI.
πΉ 2. background-image
Property
This allows you to add an image in the background of an element.
β Values:
url('image.jpg')
β Load imagenone
β No image (default)
β Real Example:
<style>
.banner {
background-image: url('https://via.placeholder.com/1200x400.png?text=Sale+Banner');
height: 300px;
background-color: #ddd;
}
</style>
<div class="banner">This banner has a background image.</div>
Use Case: Promotional banners, hero sections, login backgrounds.
πΉ 3. background-size
Property
This controls how the background image fits inside the element.
β Values:
auto
β Original size of the image (default)cover
β Image covers the entire element, cropping if neededcontain
β Image fits inside the element without cropping100% 100%
β Stretch image to fit exact size
β Real Example:
<style>
.cover {
background-image: url('https://via.placeholder.com/800x300');
background-size: cover;
height: 300px;
}
.contain {
background-size: contain;
}
</style>
<div class="cover">Cover - fills the box</div>
<div class="cover contain">Contain - shows full image</div>
Use Case:
cover
: Use for full-width banners.contain
: Use when you want the full image to be visible (e.g., logos, products).
πΉ 4. background-position
Property
This sets the starting point of the background image inside the element.
β Values:
Keywords:
top
,center
,bottom
,left
,right
Coordinates:
50px 100px
,20% 80%
β Real Example:
<style>
.positioned {
background-image: url('https://via.placeholder.com/800x300');
background-size: auto;
height: 300px;
}
.top-left {
background-position: top left;
}
.centered {
background-position: center;
}
.custom {
background-position: 100px 50px;
}
</style>
<div class="positioned top-left">Top Left</div>
<div class="positioned centered">Centered</div>
<div class="positioned custom">Custom Position</div>
Use Case: When you're aligning brand logos or decorative icons.
πΉ 5. background-repeat
Property
This controls whether the background image repeats inside the element.
β Values:
repeat
β Repeats both horizontally and vertically (default)no-repeat
β Shows image only oncerepeat-x
β Only horizontalrepeat-y
β Only vertical
β Real Example:
<style>
.repeat {
background-image: url('https://www.toptal.com/designers/subtlepatterns/patterns/pw_maze_white.png');
background-repeat: repeat;
height: 300px;
}
.no-repeat {
background-repeat: no-repeat;
background-position: center;
}
</style>
<div class="repeat">Repeating pattern</div>
<div class="repeat no-repeat">Single image centered</div>
Use Case: Repeating patterns (like textures or small icons).
πΉ 6. background
Shorthand Property
You can combine all background-related values into one line using the shorthand.
β Syntax:
background: [color] [image] [repeat] [position]/[size];
β Real Example:
<style>
.shorthand {
background: #000 url('https://via.placeholder.com/1200x400') no-repeat center/cover;
height: 300px;
color: white;
display: flex;
align-items: center;
justify-content: center;
}
</style>
<div class="shorthand">This uses background shorthand</div>
Use Case: Makes code cleaner and more readable.
π οΈ Summary Table of Properties
Property | Description |
background-color | Sets background color |
background-image | Adds image in background |
background-size | Controls image scaling (cover , contain ) |
background-position | Where image appears in the box |
background-repeat | Repeats image or not |
background | Shorthand for all the above |
π‘ Pro Tips for Working Professionals
β Use
cover
for banners to avoid empty space.β Always set a
background-color
as a fallback in case image fails.β Combine
background-*
properties usingbackground
shorthand for better performance.β Prefer compressed images (WebP/optimized JPG) for faster load time.
β Use gradient backgrounds with
linear-gradient()
for modern UI without images.
π¦ Real-World Example: Product Promotion Banner
<style>
.promo-banner {
width: 100%;
height: 400px;
background: url('https://via.placeholder.com/1200x400.png?text=Big+Sale') no-repeat center/cover;
color: white;
display: flex;
justify-content: center;
align-items: center;
font-size: 2rem;
background-color: #222; /* fallback */
}
</style>
<div class="promo-banner">
Mega Sale β 50% OFF!
</div>
π Conclusion
Background properties in CSS help you:
Improve UI appearance
Add branding elements
Enhance user experience
Whether you're a beginner building your first website or a working developer maintaining a complex layout, mastering these properties will give you a lot of design control.
π― Task Title: Create a Stylish Profile Card Web Page
π§Ύ Objective:
Students will create a visually appealing profile card using HTML & CSS by applying various background, text, and font properties.
π Task Instructions:
β Part 1: Structure using HTML
Create a web page with the following:
A main container
Inside it, one profile card
Add your name, title, a short description, and a button
<!-- Sample Structure -->
<div class="container">
<div class="profile-card">
<h1>Your Name</h1>
<h3>Your Role (e.g., Web Developer)</h3>
<p>A short description about yourself</p>
<button>Contact Me</button>
</div>
</div>
β Part 2: Style using CSS
1. Apply Background Properties
Use a background color on the full body
Use a background image for the
.profile-card
Use
background-repeat
,background-position
, andbackground-size
2. Use Font Properties
Change the font family (use at least 2 different fonts)
Set font size and font weight
Add line-height and letter-spacing
3. Style the Text
Change the text color
Use
text-align
,text-transform
,text-shadow
4. Add Button Styling
Use background color and text color
Add border-radius, padding, and hover effects
π» Output Example: What Students Should Create
A card like this:
|----------------------------------------|
| [Background image] |
| |
| Payal Sharma |
| Frontend Developer |
| I love building responsive UIs. |
| [Contact Me] (Button) |
|----------------------------------------|
π Concepts Practiced
Topic | Properties Covered |
Background | background-color, background-image, background-repeat, background-size, background-position |
Font | font-family, font-size, font-weight, line-height, letter-spacing |
Text | text-align, text-transform, text-shadow, color |
Bonus | hover effect, border-radius, padding, margin |
π§ Bonus Challenge (Optional)
Add a hover effect on the card or button
Make the card responsive (bonus for flexbox/grid use)
β Submission Instruction (if using classroom)
Submit
index.html
andstyle.css
OR host on platforms like CodePen / Replit / GitHub Pages
π Stay Connected
If you found this article helpful and want to receive more such beginner-friendly and industry-relevant CSS notes, tutorials, and project ideas β
π© Subscribe to our newsletter by entering your email below.
And if you're someone who wants to prepare for tech interviews while having a little fun and entertainment,
π₯ Donβt forget to subscribe to my YouTube channel β Knowledge Factory 22 β for regular content on tech concepts, career tips, and coding insights!
Stay curious. Keep building. π
Subscribe to my newsletter
Read articles from Payal Porwal directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Payal Porwal
Payal Porwal
Hi there, tech enthusiasts! I'm a passionate Software Developer driven by a love for continuous learning and innovation. I thrive on exploring new tools and technologies, pushing boundaries, and finding creative solutions to complex problems. What You'll Find Here On my Hashnode blog, I share: π In-depth explorations of emerging technologies π‘ Practical tutorials and how-to guides π§Insights on software development best practices πReviews of the latest tools and frameworks π‘ Personal experiences from real-world projects. Join me as we bridge imagination and implementation in the tech world. Whether you're a seasoned pro or just starting out, there's always something new to discover! Letβs connect and grow together! π