mcpField
T
theme-shopify-css-guidelines

theme-shopify-css-guidelines

github.com/niccos-shopify-workspaceDesign & UI258 installsUpdated 37w ago
Repository

About theme-shopify-css-guidelines

A set of CSS conventions for Shopify theme development, covering class naming, scoping, nesting, and file organization. It helps theme developers keep section styles semantic and contained.

Key features

  1. 01BEM class naming
  2. 02Section-scoped styles
  3. 03Limited CSS nesting
  4. 04One CSS file per section
  5. 05Semantic class names

Use cases

  1. 01Styling Shopify theme sections
  2. 02Naming component classes
  3. 03Preventing CSS leakage between sections

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/niccos-shopify-workspace/shopify-cursor-skills --skill theme-shopify-css-guidelines

After installing, type/theme-shopify-css-guidelinesin Claude Code to confirm it loaded.

Details

From the project README

Shopify CSS Guidelines

CSS naming conventions, nesting rules, and encapsulation practices for Shopify theme development.

When to Use

  • Writing CSS for Shopify theme sections
  • Naming CSS classes
  • Deciding when to use CSS nesting
  • Encapsulating section styles

CSS Naming - BEM Methodology

Use BEM (Block Element Modifier) methodology for structure inside a section:

.block {}
.block__element {}
.block__element--modifier {}
Naming Rules
  • Class names should be short, semantic, and intentional
  • Avoid generic or visual-based naming
  • Use BEM structure: .block__element--modifier
Examples
/* Good - BEM structure */
.product-card {}
.product-card__image {}
.product-card__title {}
.product-card__price {}
.product-card__button {}
.product-card__button--primary {}

/* Bad - generic or visual naming */
.red-button {}
.big-text {}
.container {}

CSS Scope & Encapsulation

Encapsulation is allowed:

  • To avoid style leakage between sections
  • To protect a section from theme-level styles
  • Only inside a section scope

Each section should have its own scoped styles to prevent conflicts.

CSS Nesting

Native CSS nesting is allowed, but with strict rules.

When to Use Nesting

Use nesting only where encapsulation is required:

  • Section-level namespacing
  • Block → element structure inside a section
  • Pseudo-classes and state modifiers
Nesting Rules
  • Nesting must stay inside a section scope
  • Keep nesting depth minimal (1–2 levels max)
  • Use nesting for BEM structure: .block { .block__element {} }
Allowed Use Cases
/* Section-level namespacing */
.featured-collection {
  padding: 2rem;
}

.featured-collection__grid {
  display: grid;
  gap: 1rem;
}

.featured-collection__item {
  /* Block element */
}

.featured-collection__item:hover {
  /* Pseudo-class */
}

.featured-collection__item--featured {
  /* Modifier */
}
Not Allowed
  • Deep nesting (more than 2 levels)
  • Cross-block dependencies
  • Assuming nested styles are globally reusable
/* Bad - too deep */
.section {
  .block {
    .element {
      .sub-element {
        /* 3+ levels - avoid */
      }
    }
  }
}

/* Bad - cross-block dependency */
.section-a {
  .section-b__element {
    /* Don't style other sections' elements */
  }
}

Section CSS Structure

Each section should have its own CSS file with scoped styles:

/* featured-collection.css */
.featured-collection {
  /* Section wrapper */
}

.featured-collection__header {
  /* Section header */
}

.featured-collection__grid {
  /* Main content area */
}

.featured-collection__item {
  /* Grid item */
}

.featured-collection__item:hover {
  /* Hover state */
}

@media (max-width: 749px) {
  .featured-collection__grid {
    /* Mobile styles */
  }
}

Shopify Theme Documentation

Reference these official Shopify resources:

Instructions

  1. Use BEM naming for all classes inside sections
  2. Keep names semantic - describe purpose, not appearance
  3. Encapsulate styles within section scope
  4. Limit nesting to 1–2 levels maximum
  5. One CSS file per section - never mix multiple sections
  6. Use nesting only for BEM structure and pseudo-classes

Comments

Markdown supported