CSS architecture patterns: BEM and utility-first approaches

Alex Chang Feb 2026
2 tabs
/* BEM - Block Element Modifier */

/* BLOCK - Independent component */
.card {
  padding: 1rem;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: white;
}

/* ELEMENT - Part of block (uses __) */
.card__header {
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #eee;
}

.card__title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: bold;
}

.card__subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.875rem;
  color: #666;
}

.card__body {
  padding: 1rem 0;
}

.card__footer {
  padding-top: 0.5rem;
  border-top: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card__image {
  width: 100%;
  height: auto;
  border-radius: 4px;
}

.card__button {
  padding: 0.5rem 1rem;
  background: #3b82f6;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

/* MODIFIER - Variation of block/element (uses --) */
.card--featured {
  border-color: #3b82f6;
  box-shadow: 0 4px 8px rgba(59, 130, 246, 0.2);
}

.card--compact {
  padding: 0.5rem;
}

.card--horizontal {
  display: flex;
  flex-direction: row;
}

.card__title--large {
  font-size: 1.75rem;
}

.card__button--secondary {
  background: #6b7280;
}

.card__button--disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* More BEM examples */
.navigation {
  display: flex;
  background: #1f2937;
}

.navigation__list {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
}

.navigation__item {
  margin: 0;
}

.navigation__link {
  display: block;
  padding: 1rem;
  color: white;
  text-decoration: none;
}

.navigation__link--active {
  background: #3b82f6;
  font-weight: bold;
}

.navigation--vertical .navigation__list {
  flex-direction: column;
}

/* Form with BEM */
.form {
  max-width: 500px;
}

.form__group {
  margin-bottom: 1rem;
}

.form__label {
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 500;
}

.form__input {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #ddd;
  border-radius: 4px;
}

.form__input--error {
  border-color: #ef4444;
}

.form__error {
  color: #ef4444;
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

.form__submit {
  padding: 0.75rem 1.5rem;
  background: #3b82f6;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.form--inline .form__group {
  display: inline-block;
  margin-right: 1rem;
}
2 files · css, html Explain with highlit

BEM (Block Element Modifier) naming uses .block__element--modifier pattern for scalable CSS. I define blocks as independent components like .card. Elements within blocks use .card__title and .card__body. Modifiers indicate variations with .card--featured or .card__title--large. BEM prevents specificity conflicts and naming collisions. Utility-first CSS uses single-purpose classes like .flex, .p-4, .text-center. I compose utilities for rapid development without writing custom CSS. Frameworks like Tailwind CSS popularized utility-first methodology. The SMACSS methodology organizes CSS into Base, Layout, Module, State, and Theme categories. ITCSS (Inverted Triangle CSS) structures from generic to specific. Understanding architecture patterns improves large-scale CSS maintainability.