CSS Properties and Values
Understand how CSS properties and values work together to style HTML. Learn proper syntax, units, and value types.
In CSS, properties define what you want to style, and values define how you want it styled.
Basic Syntax:
property: value;
Example:
color: red;
font-size: 18px;Each declaration ends with a semicolon ;, and lives inside a selector block:
p {
color: red;
font-size: 18px;
}🔧 Common Properties
| Property | What it Controls | Example Value |
|---|---|---|
color | Text color | blue, #333 |
background | Background color or image | #f0f0f0 |
font-size | Text size | 16px, 1.2em |
margin | Space outside the element | 20px, auto |
padding | Space inside the element | 10px 20px |
border | Border around element | 1px solid black |
width | Element width | 100%, 200px |
height | Element height | auto, 300px |
🔢 Types of CSS Values
- Keywords – predefined values
auto,inherit,none,block,inline - Color values –
Named (red), HEX (#ff0000), RGB (rgb(255, 0, 0)), HSL - Length units –
px,em,rem,%,vh,vw - URLs –
For images or fontsurl('image.jpg') - Functions –
calc(),rgba(),var()
✅ Example: Putting It All Together
.box {
width: 300px;
height: 200px;
background-color: #fefefe;
border: 1px solid #ccc;
padding: 20px;
color: #333;
}🧠 Tips
- Don’t forget the semicolon
;at the end of each line. - Use a code editor with IntelliSense to explore available properties.
- Not all properties work with all elements—check documentation if unsure.
Was this helpful?
Thanks for your feedback!