Lesson 3.3: Colors, Backgrounds, Borders, Fonts
In this lesson, you will learn how to style web pages using colors, backgrounds, borders, and fonts in CSS. These properties make your website visually appealing and easy to read.
1. Colors in CSS
CSS allows you to set text colors, background colors, and border colors.
Ways to define colors in CSS:
-
Color Names →
red,blue,green,black -
Hexadecimal Codes →
#ff0000(red),#000000(black) -
RGB Values →
rgb(255, 0, 0)(red) -
RGBA Values →
rgba(255, 0, 0, 0.5)(red with 50% transparency) -
HSL Values →
hsl(0, 100%, 50%)(red)
✅ Example:
2. Backgrounds in CSS
You can apply different background styles to elements.
Properties:
-
background-color→ sets background color -
background-image→ sets image as background -
background-repeat→ repeat options (repeat, no-repeat, repeat-x, repeat-y) -
background-size→ control image size (cover,contain, px, %) -
background-position→ position image (center,top left, etc.)
✅ Example:
3. Borders in CSS
Borders define the outline around an element.
Properties:
-
border-style→ solid, dashed, dotted, double, none -
border-width→ thickness (px, em, %) -
border-color→ border color -
border-radius→ for rounded corners
✅ Example:
4. Fonts in CSS
Fonts make text readable and stylish.
Properties:
-
font-family→ set font type (Arial, Verdana, etc.) -
font-size→ set text size (16px,1.5em,%) -
font-weight→ boldness (normal,bold,lighter,100–900) -
font-style→ normal, italic, oblique -
line-height→ space between lines
✅ Example:
Quick Example (All Together)
This will show an h1 heading with dark blue text, Georgia font, a red dashed border, and a yellow background.
