Skip to content

Instantly share code, notes, and snippets.

@ywwwtseng
Created December 20, 2017 07:14
Show Gist options
  • Save ywwwtseng/8f2c483eb7bd385c678cdea650ff671c to your computer and use it in GitHub Desktop.
Save ywwwtseng/8f2c483eb7bd385c678cdea650ff671c to your computer and use it in GitHub Desktop.
css naming conventions

CSS Naming Conventions

Components

A page module that has a certain purpose and is a wrapper for its children.

Naming components

.component {…}
.component-name {…}

Example:

.search-form {...}

Elements

Elements are things inside your component.

.component__link {…}
.component-name__link-element {…}

Example:

.search-form__field {...}
.search-form__action {...}

Variants

Components may have variants. Elements may have variants, too.

Naming variants

.component--variant {…}
.component-name--variant-modifier {…}

Example:

.search-form--prefixed {...}

Modifiers / State Indicators

Naming variants

A component can be modified via a separate class.

.component.active {…}

Example:

.search-form.active {...}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment