Module 1: Introduction to Web Design | Duration: 1 hr
Learning Objectives
By the end of this session, students will be able to:
Apply solid colors and transparent backgrounds to elements
Use background images with proper positioning and sizing
Create linear and radial gradients for modern designs
Style borders with colors, widths, and styles
Create rounded corners using border-radius
Combine background and border properties for attractive designs
Introduction
Background and border properties are essential for creating visually appealing web designs. These properties allow you to add colors, images, gradients, and decorative borders to elements, transforming basic HTML into beautiful, professional-looking websites.
Key Insight
Modern CSS provides powerful background and border capabilities including multiple backgrounds, complex gradients, and flexible border styling. These properties are fundamental to creating engaging user interfaces.
Background Color
The background-color property sets the background color of an element.
Color Value Types
/* Named colors (140+ color names) */
background-color: red;
background-color: lightblue;
background-color: cornflowerblue;
/* Hexadecimal notation */
background-color: #ff0000; /* Red */
background-color: #0000ff; /* Blue */
background-color: #3498db; /* Light Blue */
/* RGB notation */
background-color: rgb(255, 0, 0); /* Red */
background-color: rgb(52, 152, 219); /* Light Blue */
/* RGBA (with transparency) */
background-color: rgba(255, 0, 0, 0.5); /* Semi-transparent red */
background-color: rgba(0, 0, 0, 0.8); /* 80% opaque black */
/* HSL (Hue, Saturation, Lightness) */
background-color: hsl(0, 100%, 50%); /* Red */
background-color: hsl(204, 70%, 53%); /* Light Blue */
/* HSLA (with transparency) */
background-color: hsla(0, 100%, 50%, 0.5); /* Semi-transparent red */
/* Transparent */
background-color: transparent;
Visual Examples
#e74c3c Hex Red
RGB 46, 204, 113
RGBA 70% Opaque
HSL Purple
Color Format Comparison
Hex: Most common, compact, easy to copy
RGB/RGBA: Intuitive, supports transparency
HSL/HSLA: Best for creating color variations, adjusting brightness
Named colors: Easy to remember but limited palette
Background Image
Background images add visual interest and can be combined with other background properties for sophisticated designs.
Background Image Properties
/* Basic background image */
.hero {
background-image: url('images/hero.jpg');
}
/* Background repeat control */
background-repeat: repeat; /* Default - tiles in both directions */
background-repeat: repeat-x; /* Repeats horizontally only */
background-repeat: repeat-y; /* Repeats vertically only */
background-repeat: no-repeat; /* Shows once */
/* Background position */
background-position: center; /* Center both axes */
background-position: top left; /* Top-left corner */
background-position: 50% 50%; /* Percentage positioning */
background-position: 20px 30px; /* Pixel positioning */
/* Background size */
background-size: auto; /* Original size */
background-size: cover; /* Covers entire element, may crop */
background-size: contain; /* Fits within element, may show gaps */
background-size: 100% 100%; /* Stretches to fit */
background-size: 500px 300px; /* Specific dimensions */
/* Background attachment */
background-attachment: scroll; /* Scrolls with content (default) */
background-attachment: fixed; /* Fixed to viewport (parallax effect) */
Background Color: Use hex, RGB, RGBA, HSL, or named colors for backgrounds
Background Image: Control positioning, size, repeat, and attachment for images
Gradients: Create linear, radial, and conic gradients without images
Multiple Backgrounds: Layer multiple images and gradients for complex designs
Borders: Style with various widths, styles (solid, dashed, dotted), and colors
Border Radius: Create rounded corners and shapes from subtle to circular
Best Practices
Use background-size: cover for hero sections and full-width images
Combine gradients with images for overlay effects
Keep gradients subtle for professional designs
Use border-radius consistently throughout your design
Consider accessibility with sufficient color contrast
Optimize background images for web performance
Next Session Preview
In the next session, we'll explore CSS Grid Layout, a powerful two-dimensional layout system that revolutionizes how we create complex web layouts with clean, maintainable code.