CSS properties and values are the building blocks used to describe how HTML elements should look and behave. A selector identifies the element you want to style, while a CSS declaration tells the browser which property to change and what value to use.
For example, when you write color: orange;,
color is the property and orange is the value.
Together they form a CSS declaration that changes the text color of the matching element.
The Basic CSS Relationship
Selector
Determines which HTML elements are targeted.
Property
Defines what aspect of the element you want to control.
Value
Defines the setting or behavior for that property.
What Is a CSS Property?
A CSS property represents a specific aspect of an element
that CSS can control.
Examples include color, font-size, width,
margin, padding, display, and background-color.
.card {
color: #1e293b;
width: 300px;
padding: 20px;
background-color: white;
}
In this example, all four names are CSS properties. Each property controls a different aspect of the card.
What Is a CSS Value?
A CSS value specifies the setting assigned to a property. Different properties accept different kinds of values.
color: orange;
font-size: 20px;
width: 100%;
display: flex;
Here, orange, 20px, 100%,
and flex are values.
The browser interprets each value according to the property it belongs to.
What Is a CSS Declaration?
A declaration consists of a property and its value, separated by a colon and normally terminated with a semicolon.
How Do CSS Properties and Values Fit into a Rule?
A complete CSS rule usually contains a selector and one or more declarations.
.title {
color: #f97316;
font-size: 2rem;
font-weight: 700;
}
The selector is .title.
The declaration block contains three declarations:
color: #f97316;font-size: 2rem;font-weight: 700;
Why Do Different CSS Properties Accept Different Values?
CSS properties are designed to represent different types of styling behavior. A property therefore accepts values that make sense for that property.
| Property | Example Values |
|---|---|
color |
red, #f97316, rgb(...) |
width |
300px, 50%, 20rem |
display |
block, flex, grid |
font-weight |
400, 700, bold |
margin |
20px, auto, 1rem 2rem |
What Types of CSS Values Are Common?
CSS supports many value types. You will frequently work with keywords, numbers, lengths, percentages, colors, functions, strings, and lists of values.
Keyword Values
Keyword values are predefined words that represent supported CSS behavior.
display: block;
position: relative;
font-weight: bold;
overflow: hidden;
Length Values
Length values represent dimensions such as spacing, width, height, and font size.
width: 300px;
padding: 1rem;
font-size: 20px;
margin-top: 2rem;
Percentage Values
Percentages allow a value to be expressed relative to another relevant dimension or context.
width: 50%;
max-width: 100%;
padding-inline: 5%;
Color Values
CSS colors can be represented in several formats, including named colors, hexadecimal notation, RGB functions, and HSL functions.
.example {
color: orange;
color: #f97316;
color: rgb(249 115 22);
color: hsl(24 94% 53%);
}
Function Values
CSS functions perform calculations, generate values, or provide more flexible styling behavior.
width: calc(100% - 2rem);
font-size: clamp(
1.5rem,
4vw,
3rem
);
background: rgb(
15 23 42
);
What Are CSS Global Keywords?
CSS also provides special global keywords that can control how a property's value is determined.
Common examples include inherit, initial, unset,
and revert.
.child {
color: inherit;
}
.title {
font-size: initial;
}
.panel {
all: unset;
}
These keywords are useful when you need to explicitly control inheritance or return a property to another defined behavior.
Can One Property Have Multiple Values?
Yes. Some properties accept multiple values to describe different sides, layers, or parts of a value.
.card {
margin: 10px 20px 30px 40px;
padding: 1rem 2rem;
box-shadow:
0 10px 30px rgb(0 0 0 / 15%);
}
The meaning of multiple values depends on the property. You should learn the value syntax associated with each property instead of assuming that every property interprets multiple values in the same way.
How Do CSS Units Work?
CSS properties that represent dimensions often use units. Some units are based on fixed physical-style dimensions while others are relative to a font size, viewport, or another containing dimension.
Absolute-style Length
20px
Common for precise UI dimensions and borders.
Relative Length
1rem
Relative to the root element's font size.
Percentage
50%
Depends on the property's relevant reference context.
Viewport Unit
50vw
Useful for sizing relative to viewport dimensions.
How Do CSS Color Properties Work?
Color-related properties control text, backgrounds, borders, outlines, shadows, and other visual elements.
body {
color: #1e293b;
background-color: #f8fafc;
}
.card {
border-color: #cbd5e1;
}
.button {
background-color: #f97316;
color: white;
}
How Do Typography Properties Work?
CSS provides many properties for controlling text presentation.
Common properties include font-family, font-size,
font-weight, line-height, text-align,
and letter-spacing.
body {
font-family:
Arial,
sans-serif;
color: #1e293b;
line-height: 1.6;
}
h1 {
font-size: 2.5rem;
font-weight: 700;
letter-spacing: -0.02em;
}
p {
text-align: left;
}
How Do CSS Sizing Properties Work?
Properties such as width, height, min-width,
max-width, min-height, and max-height
control the dimensions and constraints of elements.
.container {
width: 100%;
max-width: 900px;
min-height: 300px;
}
Combining a flexible width with a maximum width is a common pattern for responsive containers.
How Do CSS Spacing Properties Work?
Spacing properties control the space inside or outside elements.
The most familiar examples are margin and padding.
.card {
margin: 30px auto;
padding: 24px;
}
For Flexbox and Grid layouts, gap is another important spacing property.
.cards {
display: grid;
gap: 1.5rem;
}
How Do Display Properties Use Keyword Values?
The display property demonstrates how CSS properties can use predefined keyword values.
display: block;
Creates a block-level outer display type.
display: flex;
Establishes a flex formatting context.
display: grid;
Establishes a grid formatting context.
What Happens When a CSS Value Is Invalid?
CSS values must be valid for the property receiving them. When a declaration contains a value that does not conform to the property's accepted syntax, the browser does not use that invalid declaration as intended.
.card {
width: banana;
}
banana is not a valid value for the width property.
This is why learning the expected value types of common CSS properties is important.
What Is the Difference Between a Property and a Value?
| Concept | Example | Meaning |
|---|---|---|
| Property | color |
The aspect being controlled |
| Value | orange |
The setting assigned to the property |
Can a CSS Property Have Different Types of Values?
Yes.
Many CSS properties accept multiple value types.
For example, width can commonly accept lengths,
percentages, and other supported sizing values.
.box-one {
width: 300px;
}
.box-two {
width: 50%;
}
.box-three {
width: 20rem;
}
These declarations are different ways of expressing the size depending on the layout requirements.
What Are CSS Shorthand Properties?
Some properties allow several related values to be written in a compact form. These are commonly called shorthand properties.
.card {
margin: 10px 20px 30px 40px;
padding: 16px 24px;
border: 1px solid #cbd5e1;
}
Shorthand can reduce repetition, but the exact interpretation depends on the property. Make sure you understand the property's syntax before using compact forms.
What Is CSS Inheritance?
Some CSS properties can inherit their computed values from a parent element. This is useful for properties such as many text-related styles.
body {
color: #334155;
}
.card {
/* The color may be inherited
by descendants. */
}
Not every property inherits by default. Whether a property inherits is part of that property's behavior.
How Do Properties and Values Work with the Cascade?
Multiple CSS declarations can target the same element and property. The CSS cascade determines which declaration is applied after considering the relevant cascade rules, including origin, importance, layers, specificity, and source order where applicable.
p {
color: blue;
}
.article p {
color: orange;
}
Both declarations use the same property, but the browser must resolve the conflict before determining the final color. This is why understanding properties alone is not enough; you also need to understand how the cascade chooses between competing declarations.
How Do CSS Custom Properties Work?
CSS custom properties allow developers to define reusable values. They are especially useful for design systems and application-wide tokens.
:root {
--primary-color: #f97316;
--text-color: #1e293b;
--spacing-md: 1rem;
}
.button {
background: var(--primary-color);
color: white;
padding: var(--spacing-md);
}
.card {
color: var(--text-color);
}
The property --primary-color is a custom property,
and var(--primary-color) retrieves its value.
Choosing Good Property and Value Combinations
Writing CSS effectively means choosing a property that represents the actual problem and a value that expresses the desired behavior.
Change Text Color
.title {
color: #f97316;
}
Add Internal Space
.card {
padding: 24px;
}
Create a Grid
.cards {
display: grid;
}
Limit Width
.content {
max-width: 70ch;
}
Common CSS Properties for Beginners
| Property | Used For | Example |
|---|---|---|
color |
Text color | color: red; |
background-color |
Background color | background-color: white; |
font-size |
Text size | font-size: 18px; |
width |
Element width | width: 100%; |
padding |
Internal spacing | padding: 20px; |
margin |
External spacing | margin: 20px; |
display |
Layout behavior | display: flex; |
border |
Element boundary | border: 1px solid; |
What Happens When You Use the Wrong Property?
CSS only works when the chosen property addresses the problem you are trying to solve. For example, padding is for internal spacing, while margin is for external spacing. Using a visually convenient property without understanding its layout meaning can lead to difficult-to-maintain CSS.
/* Do not use random properties
just to move content */
.card {
margin-top: 20px;
}
The correct property depends on what you are trying to change. Understanding CSS concepts such as the box model, layout, positioning, and inheritance helps you make better property choices.
How to Read CSS More Easily
When reading a CSS rule, break it into three questions:
Identify the selector.
Identify the property.
Identify the value.
.card {
padding: 24px;
}
Here:
.cardis the selected component.paddingis the property being changed.24pxis the value assigned to that property.
Common CSS Properties and Their Categories
Typography
font-family, font-size, font-weight,
line-height, text-align
Colors and Backgrounds
color, background-color, background-image
Box Model
width, height, padding,
margin, border
Layout
display, position, flex,
grid-template-columns, gap
Best Practices for CSS Properties and Values
Choose Properties Based on the Problem
Understand whether you are changing appearance, spacing, dimensions, layout, positioning, or interaction before selecting a property.
Use Appropriate Units
Select fixed or relative units based on the layout and responsive requirements.
Reuse Meaningful Values
Shared colors, spacing, and design values can be centralized with CSS custom properties.
Avoid Invalid Values
Learn which value types are supported by the property you are using.
Understand Shorthand
Shorthand reduces repetition, but you should understand exactly how its values are interpreted.
Key Takeaways
A CSS property represents an aspect of an element that you want to control.
A CSS value defines the setting assigned to that property.
A declaration combines a property and value, such as color: orange;.
Different CSS properties accept different value types, including keywords, lengths, percentages, colors, functions, and more.
CSS properties can also accept multiple values through shorthand or property-specific syntax.
Global keywords such as inherit, initial,
unset, and revert provide additional control over values.
CSS custom properties allow reusable values to be defined and consumed across components.
The CSS cascade determines which declaration wins when multiple rules compete.
The most important skill is not memorizing every CSS property, but understanding what problem each property solves and what kinds of values it accepts.