-
Notifications
You must be signed in to change notification settings - Fork 10.8k
CSS SASS coding guidelines and naming conventions
Our guidelines are based on those used in Calypso which itself follows the BEM methodology. Refer to this doc for full details. There are a few differences in WooCommerce however which are outlined below;
As a WordPress plugin WooCommerce has to play nicely with WordPress core and other plugins / themes. To minimise conflict potential all classes should be prefixed with .woocommerce-
.
Calypso is built in React and uses component names to formulate CSS class names. WooCommerce Core has none of these components so uses a more traditional BEM approach to naming classes.
When adding classes just remember;
- Block - Standalone entity that is meaningful on its own.
- Element - Parts of a block and have no standalone meaning. They are semantically tied to its block.
- Modifier - Flags on blocks or elements. Use them to change appearance or behaviour.
-
.woocommerce-loop {}
(block). -
.woocommerce-loop-product {}
(nested block). -
.woocommerce-loop-product--sale {}
(modifier). -
.woocommerce-loop-product__link {}
(element). -
.woocommerce-loop-product__title {}
(element). -
.woocommerce-loop-product__price {}
(element). -
.woocommerce-loop-product__rating {}
(element). -
.woocommerce-loop-product__button-add-to-cart {}
(element). -
.woocommerce-loop-product__button-add-to-cart--added {}
(modifier).
Note: .woocommerce-loop-product
is not the chosen classname because the block is nested within .woocommerce-loop
. It's to be specific so that we can have separate classes for single products, cart products etc. Nested blocks do not need to inherit their parents full name.
You can read more about BEM key concepts here.
TL;DR
- Follow the WP Coding standards for CSS unless it contradicts anything here.
- Follow Calypso guidelines.
- Use BEM for class names.
- Prefix all the things.
WooCommerce is an open source commerce platform built for WordPress and lovingly crafted by Automattic and the WooCommerce community 💜. Come and work with us!
Contribution
- Set up development environment
- Our Git Flow
- SCSS and JS minification
- Naming conventions
- CSS SASS coding guidelines and naming conventions
- Critical Flows
- API Critical Flows
- String localisation guidelines
- Translating WooCommerce
- Deprecation in core
- Adding Actions and Filters
- Common Issues
- Writing high-quality testing instructions
Release Notes
- Release Testing Instructions
- 3.6.x notes/FAQ
- 2.6.x to 3.0.0 Developer Migration Notes
- Select2 fields not working in 3.0.x
- Thumbnail Image Regeneration in 3.3+
- Customizing image sizes in 3.3+
REST API and CLI
CRUD & Data Descriptions
- Database Description
- CRUD Objects in 3.0
- Order and Order Line Item Data
- Coupon Data
- Customer Data
- Product Data
- Data Stores
Internal APIs
Theming
- Enabling product gallery features (zoom, swipe, lightbox)
- Template File Guidelines for Devs and Theme Authors
Examples / Guides