📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials CSS Mastery CSS Nesting

CSS Nesting

5 min read
Native CSS nesting lets you write rules inside parent selectors without a preprocessor. .card { color: blue; &:hover { color: red; } } The & represents the parent selector. Great for keeping responsive styles together.

CSS Nesting (Modern)

/* Supported in modern browsers — no preprocessor needed! */
.card {
    background: white;
    padding: 1rem;

    & h2 {
        font-size: 1.5rem;
        margin-bottom: 0.5rem;
    }

    & p {
        color: #6b7280;
    }

    &:hover {
        box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    }

    @media (max-width: 600px) {
        padding: 0.5rem;
    }
}