CSS Nesting Selectors

Use native CSS nesting to organize selectors hierarchically without preprocessor dependencies for cleaner stylesheets.

CssConfig Management

Code

.card {
  padding: 1rem;
  border-radius: 8px;
  
  & .title {
    font-size: 1.25rem;
    font-weight: bold;
  }
  
  &:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  }
}

CSS Nesting Selectors

Use native CSS nesting to organize selectors hierarchically without preprocessor dependencies for cleaner stylesheets.

Code

.card {
  padding: 1rem;
  border-radius: 8px;
  
  & .title {
    font-size: 1.25rem;
    font-weight: bold;
  }
  
  &:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  }
}

Explanation

Native & nesting groups child selectors under a parent so stylesheets read hierarchically without a preprocessor. Expected behavior: the nested rules match with the same specificity as if they were written out flat. Caveat: without &, a nested type selector is implicitly descendant-scoped, which can broaden or narrow matches unexpectedly.

Interactive Tools for This Topic