Introduction to CSS3 Properties
CSS3 (Cascading Style Sheets Level 3) represents the evolution of the CSS standard, introducing powerful styling capabilities that transform the way we design web pages. CSS3 properties control everything from layout and typography to animations and visual effects, enabling responsive, interactive, and visually appealing web experiences without relying on images or JavaScript for many effects.
Core CSS Property Concepts
CSS Property Syntax
selector {
property: value;
}
CSS Property Value Types
• Keywords: auto, none, inherit • Length units: px, em, rem, vh, vw • Percentages: 50%, 100% • Colors: #FF0000, rgb(255,0,0), rgba(255,0,0,0.5), hsl(0,100%,50%) • URLs: url('image.jpg') • Functions: calc(), var(), linear-gradient()
CSS Property Inheritance
• Some properties inherit from parent elements (e.g., color, font-family) • Others don’t inherit by default (e.g., margin, padding) • Force inheritance with inherit keyword
Layout Properties
Box Model Properties
| Property | Description | Example Values |
|---|---|---|
width | Element width | 100px, 50%, auto |
height | Element height | 200px, 50vh, auto |
max-width | Maximum width | 800px, 100% |
min-width | Minimum width | 200px, 50% |
max-height | Maximum height | 400px, 100vh |
min-height | Minimum height | 100px, 20vh |
box-sizing | How width/height are calculated | content-box, border-box |
margin | Outer spacing | 10px, 1em 2em, auto |
padding | Inner spacing | 10px, 1em 2em 3em 4em |
Display and Positioning
| Property | Description | Example Values |
|---|---|---|
display | Element rendering type | block, inline, flex, grid, none |
position | Positioning method | static, relative, absolute, fixed, sticky |
top | Position from top | 0, 10px, 50% |
right | Position from right | 0, 10px, 50% |
bottom | Position from bottom | 0, 10px, 50% |
left | Position from left | 0, 10px, 50% |
z-index | Stack order | 0, 1, 100, auto |
float | Float element | left, right, none |
clear | Control flow next to floats | left, right, both |
overflow | Content overflow behavior | visible, hidden, scroll, auto |
visibility | Element visibility | visible, hidden, collapse |
opacity | Element transparency | 0 to 1 |
Flexbox Properties
Flex Container:
.container {
display: flex;
flex-direction: row | column | row-reverse | column-reverse;
flex-wrap: nowrap | wrap | wrap-reverse;
flex-flow: row wrap; /* shorthand for direction and wrap */
justify-content: flex-start | flex-end | center | space-between | space-around | space-evenly;
align-items: stretch | flex-start | flex-end | center | baseline;
align-content: flex-start | flex-end | center | space-between | space-around | stretch;
gap: 10px; /* spacing between items */
row-gap: 10px;
column-gap: 20px;
}
Flex Items:
.item {
order: 0; /* default is 0 */
flex-grow: 0; /* default is 0 */
flex-shrink: 1; /* default is 1 */
flex-basis: auto; /* default is auto */
flex: 0 1 auto; /* grow shrink basis */
align-self: auto | flex-start | flex-end | center | baseline | stretch;
}
Grid Properties
Grid Container:
.container {
display: grid;
grid-template-columns: 100px 100px | repeat(3, 1fr) | minmax(100px, 1fr);
grid-template-rows: 100px 100px | auto 1fr;
grid-template-areas: "header header" "sidebar main" "footer footer";
grid-template: auto 1fr / auto 1fr auto; /* shorthand */
grid-column-gap: 10px;
grid-row-gap: 15px;
gap: 15px 10px; /* row-gap column-gap */
justify-items: start | end | center | stretch;
align-items: start | end | center | stretch;
justify-content: start | end | center | stretch | space-around | space-between | space-evenly;
align-content: start | end | center | stretch | space-around | space-between | space-evenly;
grid-auto-columns: 100px | min-content;
grid-auto-rows: 100px | min-content;
grid-auto-flow: row | column | dense;
}
Grid Items:
.item {
grid-column-start: 1;
grid-column-end: 3;
grid-row-start: 1;
grid-row-end: 3;
grid-column: 1 / 3; /* shorthand for column-start/end */
grid-row: 1 / 3; /* shorthand for row-start/end */
grid-area: header | 1 / 1 / 3 / 3; /* shorthand for row-start/column-start/row-end/column-end */
justify-self: start | end | center | stretch;
align-self: start | end | center | stretch;
}
Typography Properties
Font Properties
| Property | Description | Example Values |
|---|---|---|
font-family | Font family | Arial, sans-serif, "Times New Roman", serif |
font-size | Font size | 16px, 1.2em, 100% |
font-weight | Font weight | normal, bold, 700 |
font-style | Font style | normal, italic, oblique |
font-variant | Font variant | normal, small-caps |
font-stretch | Font stretch | normal, condensed, expanded |
font | Shorthand | italic bold 16px/1.5 Arial, sans-serif |
line-height | Line height | 1.5, 20px, 150% |
letter-spacing | Letter spacing | normal, 2px |
word-spacing | Word spacing | normal, 5px |
text-align | Text alignment | left, right, center, justify |
text-decoration | Text decoration | none, underline, line-through |
text-transform | Text transformation | none, uppercase, lowercase, capitalize |
text-indent | Text indentation | 20px, 2em |
text-shadow | Text shadow | 2px 2px 4px rgba(0,0,0,0.3) |
white-space | White space handling | normal, nowrap, pre, pre-line, pre-wrap |
word-break | Word breaking | normal, break-all, keep-all |
word-wrap | Word wrapping | normal, break-word |
text-overflow | Text overflow | clip, ellipsis |
Modern Typography Properties
| Property | Description | Example Values |
|---|---|---|
font-display | Font loading behavior | auto, block, swap, fallback, optional |
font-feature-settings | OpenType features | "liga", "kern", "smcp" |
hyphens | Hyphenation | none, manual, auto |
text-underline-position | Underline position | auto, under |
text-underline-offset | Underline offset | 3px, 0.1em |
text-decoration-thickness | Decoration thickness | auto, 2px, 0.1em |
writing-mode | Text direction | horizontal-tb, vertical-rl, vertical-lr |
Color and Background Properties
Color Properties
| Property | Description | Example Values |
|---|---|---|
color | Text color | red, #FF0000, rgb(255,0,0), rgba(255,0,0,0.5) |
opacity | Element opacity | 1, 0.5, 0 |
color-scheme | Preferred color scheme | normal, light, dark, light dark |
Background Properties
| Property | Description | Example Values |
|---|---|---|
background-color | Background color | white, #FFFFFF, rgba(255,255,255,0.5) |
background-image | Background image | url('image.jpg'), linear-gradient(to right, red, blue) |
background-repeat | Image repetition | repeat, no-repeat, repeat-x, repeat-y |
background-position | Image position | center, top left, 50% 25% |
background-size | Image size | auto, cover, contain, 100% 100% |
background-attachment | Image scrolling | scroll, fixed, local |
background-clip | Paint area | border-box, padding-box, content-box, text |
background-origin | Positioning area | border-box, padding-box, content-box |
background-blend-mode | Blending mode | normal, multiply, screen, overlay |
background | Shorthand | #f00 url('bg.jpg') no-repeat center/cover |
Gradient Properties
/* Linear Gradient */
background-image: linear-gradient(to right, red, orange, yellow);
background-image: linear-gradient(45deg, blue, green);
/* Radial Gradient */
background-image: radial-gradient(circle, red, yellow, green);
background-image: radial-gradient(ellipse at top, white, blue);
/* Conic Gradient */
background-image: conic-gradient(red, yellow, green, blue, purple);
background-image: conic-gradient(from 45deg, red, blue);
/* Repeating Gradients */
background-image: repeating-linear-gradient(to right, red, blue 50px);
background-image: repeating-radial-gradient(circle, red, blue 20px, red 40px);
Border and Outline Properties
| Property | Description | Example Values |
|---|---|---|
border-width | Border width | 1px, thin, medium, thick |
border-style | Border style | solid, dashed, dotted, double |
border-color | Border color | black, #000, rgb(0,0,0) |
border | Shorthand | 1px solid black |
border-radius | Rounded corners | 5px, 50%, 10px 20px 30px 40px |
border-image | Border image | url('border.png') 30 stretch |
outline-width | Outline width | 1px, thin, medium, thick |
outline-style | Outline style | solid, dashed, dotted |
outline-color | Outline color | black, #000, rgb(0,0,0) |
outline | Shorthand | 1px solid black |
outline-offset | Space between outline and border | 2px, -2px |
box-shadow | Element shadow | 2px 2px 5px rgba(0,0,0,0.3) |
Transition and Animation Properties
Transition Properties
| Property | Description | Example Values |
|---|---|---|
transition-property | Properties to transition | all, opacity, transform |
transition-duration | Duration of transition | 0.3s, 300ms |
transition-timing-function | Timing curve | ease, linear, cubic-bezier(0.1, 0.7, 1.0, 0.1) |
transition-delay | Delay before starting | 0s, 0.1s, 100ms |
transition | Shorthand | all 0.3s ease 0s |
Animation Properties
| Property | Description | Example Values |
|---|---|---|
animation-name | Name of keyframe | fade, slide, pulse |
animation-duration | Duration of animation | 1s, 500ms |
animation-timing-function | Timing curve | ease, linear, cubic-bezier(0.1, 0.7, 1.0, 0.1) |
animation-delay | Delay before starting | 0s, 0.5s |
animation-iteration-count | Number of times to play | 1, 2, infinite |
animation-direction | Play direction | normal, reverse, alternate, alternate-reverse |
animation-fill-mode | Styles before/after playing | none, forwards, backwards, both |
animation-play-state | Running or paused | running, paused |
animation | Shorthand | fade 1s ease 0s infinite alternate forwards |
Transform Properties
transform: none;
transform: translate(50px, 100px);
transform: translateX(50px);
transform: translateY(100px);
transform: translateZ(10px);
transform: translate3d(50px, 100px, 10px);
transform: scale(2);
transform: scaleX(2);
transform: scaleY(0.5);
transform: scaleZ(0.3);
transform: scale3d(2, 0.5, 0.3);
transform: rotate(45deg);
transform: rotateX(45deg);
transform: rotateY(45deg);
transform: rotateZ(45deg);
transform: rotate3d(1, 1, 1, 45deg);
transform: skew(10deg, 20deg);
transform: skewX(10deg);
transform: skewY(20deg);
transform: perspective(100px);
transform: matrix(1, 0, 0, 1, 0, 0);
transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
/* Multiple transforms */
transform: translateX(50px) rotate(45deg) scale(1.5);
/* Transform origin */
transform-origin: center;
transform-origin: top left;
transform-origin: 50% 50%;
transform-origin: 100px 200px;
/* 3D properties */
transform-style: flat | preserve-3d;
perspective: none | 800px;
perspective-origin: center | top left | 50% 50%;
backface-visibility: visible | hidden;
Filter Properties
filter: none;
filter: blur(5px);
filter: brightness(0.8);
filter: contrast(150%);
filter: drop-shadow(16px 16px 20px blue);
filter: grayscale(50%);
filter: hue-rotate(90deg);
filter: invert(75%);
filter: opacity(25%);
filter: saturate(30%);
filter: sepia(60%);
/* Multiple filters */
filter: contrast(175%) brightness(103%);
/* Backdrop filters (applied to background) */
backdrop-filter: blur(10px);
backdrop-filter: brightness(60%) blur(5px);
Variable Properties (Custom Properties)
/* Defining variables */
:root {
--main-color: #4d4e53;
--main-bg: rgb(255, 255, 255);
--logo-border-color: rebeccapurple;
--header-height: 68px;
--content-padding: 10px 20px;
--base-line-height: 1.5;
--transition-duration: 0.35s;
--external-link: "external link";
--margin-top: calc(2vh + 20px);
}
/* Using variables */
.element {
color: var(--main-color);
background-color: var(--main-bg);
padding: var(--content-padding);
height: calc(var(--header-height) * 2);
transition: all var(--transition-duration) ease;
/* Fallback value if variable is not defined */
margin: var(--margin, 10px);
}
Responsive Design Properties
Media Queries
/* Based on viewport width */
@media (max-width: 767px) { /* Mobile */ }
@media (min-width: 768px) and (max-width: 991px) { /* Tablet */ }
@media (min-width: 992px) { /* Desktop */ }
/* Based on orientation */
@media (orientation: portrait) { }
@media (orientation: landscape) { }
/* Based on display quality */
@media (resolution: 300dpi) { }
@media (min-resolution: 2dppx) { }
/* Based on user preferences */
@media (prefers-color-scheme: dark) { }
@media (prefers-reduced-motion: reduce) { }
@media (prefers-contrast: high) { }
@media print { }
Viewport Units
| Unit | Description | Example Values |
|---|---|---|
vw | % of viewport width | 50vw, 100vw |
vh | % of viewport height | 50vh, 100vh |
vmin | % of viewport’s smaller dimension | 50vmin |
vmax | % of viewport’s larger dimension | 50vmax |
lvw | % of large viewport width | 50lvw |
lvh | % of large viewport height | 50lvh |
svw | % of small viewport width | 50svw |
svh | % of small viewport height | 50svh |
dvw | % of dynamic viewport width | 50dvw |
dvh | % of dynamic viewport height | 50dvh |
List and Table Properties
List Properties
| Property | Description | Example Values |
|---|---|---|
list-style-type | Bullet or numbering style | disc, circle, square, decimal, lower-roman |
list-style-position | Bullet position | inside, outside |
list-style-image | Custom bullet image | url('bullet.png') |
list-style | Shorthand | square outside |
Table Properties
| Property | Description | Example Values |
|---|---|---|
border-collapse | Border model | separate, collapse |
border-spacing | Space between cells | 2px, 2px 5px |
caption-side | Caption position | top, bottom |
empty-cells | Empty cell borders | show, hide |
table-layout | Table layout algorithm | auto, fixed |
vertical-align | Cell content alignment | baseline, top, middle, bottom |
Common Challenges & Solutions
Cross-Browser Compatibility
/* Vendor prefixes for better compatibility */
.element {
-webkit-transform: translateX(10px); /* Safari */
-moz-transform: translateX(10px); /* Firefox */
-ms-transform: translateX(10px); /* IE */
-o-transform: translateX(10px); /* Opera */
transform: translateX(10px); /* Standard */
}
/* Feature queries for progressive enhancement */
@supports (display: grid) {
.container {
display: grid;
}
}
Creating Responsive Images
/* Fluid images */
img {
max-width: 100%;
height: auto;
}
/* Background image responsive scaling */
.hero {
background-image: url('image.jpg');
background-size: cover;
background-position: center;
}
/* Art direction with media queries */
@media (max-width: 767px) {
.hero {
background-image: url('image-small.jpg');
}
}
Handling Text Overflow
/* Ellipsis for single line */
.truncate-single {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/* Multi-line ellipsis with line clamp */
.truncate-multi {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
Best Practices & Tips
• Use Shorthand Properties – Combine related properties when possible
/* Instead of */
margin-top: 10px;
margin-right: 15px;
margin-bottom: 10px;
margin-left: 15px;
/* Use shorthand */
margin: 10px 15px;
• Choose Appropriate Units
pxfor borders, shadows, precise controlem/remfor typography and spacing (responsive to font sizes)%for responsive layouts relative to parentvh/vwfor viewport-relative sizing
• Specificity Management
- Avoid using
!importantwhen possible - Use classes instead of IDs for styling
- Minimize nesting selectors
• Performance Optimization
- Use
transformandopacityfor animations - Minimize repaints with
will-change - Avoid expensive properties that trigger layout
• Layout Strategy
- Use Grid for two-dimensional layouts
- Use Flexbox for one-dimensional layouts
- Combine both for complex interfaces
• Mobile-First Approach
- Start with styles for mobile devices
- Add complexity for larger screens with media queries
• Design System Integration
- Use CSS variables for theme colors, spacing, etc.
- Maintain consistent values across components
• Progressive Enhancement
- Use
@supportsto provide fallbacks for newer features - Test across browsers and devices
Newer CSS Properties to Watch
| Property | Description | Example Values | Browser Support |
|---|---|---|---|
aspect-ratio | Set width-to-height ratio | 16 / 9, 1 / 1 | Good |
accent-color | Highlight color for UI controls | #ff0000, blue | Good |
content-visibility | Skip rendering off-screen | auto, hidden | Moderate |
font-display | Font loading behavior | swap, block, fallback | Good |
gap (for flexbox) | Space between flex items | 10px, 1rem | Good |
scroll-behavior | Smooth scrolling | auto, smooth | Good |
text-underline-offset | Adjust underline position | 3px, 0.1em | Good |
mix-blend-mode | Blending with content beneath | multiply, screen, overlay | Good |
container-type | Container query context | normal, size, inline-size | Moderate |
container-query | Style based on container size | (min-width: 700px) | Moderate |
Resources for Further Learning
• Official Documentation:
• Browser Compatibility:
• Tools:
• Learning Resources:
- CSS-Tricks
- Smashing Magazine
- web.dev
- “CSS: The Definitive Guide” by Eric Meyer
- “CSS Secrets” by Lea Verou
• Modern CSS Frameworks:
- Tailwind CSS
- Bootstrap 5
- Bulma
- Foundation
This cheatsheet covers most CSS3 properties you’ll need for modern web development. As CSS continues to evolve, check the official documentation for the latest features and browser support information.
