title: SUIT CSS naming conventions
url: https://github.com/suitcss/suit/blob/master/doc/naming-conventions.md
hash_url: 40b989f3f54a5df59c66a2ad36b7861c

<p>SUIT CSS relies on <em>structured class names</em> and <em>meaningful hyphens</em> (i.e., not
using hyphens merely to separate words). This helps to work around the current
limits of applying CSS to the DOM (i.e., the lack of style encapsulation), and
to better communicate the relationships between classes.</p>

<p>The primary architectural division is between <strong><a href="https://github.com/suitcss/suit/blob/master/doc/utilities.md">utilities</a></strong> and
<strong><a href="https://github.com/suitcss/suit/blob/master/doc/components.md">components</a></strong>.</p>

<p>Low-level structural and positional traits. Utilities can be applied directly
to any element within a component.</p>

<p>Syntax: <code>u-[sm|md|lg-]&lt;utilityName&gt;</code></p>

<h3>
<a id="user-content-u-utilityname" class="anchor" href="#u-utilityname" aria-hidden="true"><span class="octicon octicon-link"/></a>u-utilityName</h3>

<p>Utilities must use a camel case name. What follows is an example of how various
utilities can be used to create a simple structure within a component.</p>

<div class="highlight highlight-html"><pre>&lt;<span class="pl-ent">div</span> <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>u-cf<span class="pl-pds">"</span></span>&gt;
  &lt;<span class="pl-ent">a</span> <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>u-floatLeft<span class="pl-pds">"</span></span> <span class="pl-e">href</span>=<span class="pl-s"><span class="pl-pds">"</span>{{url}}<span class="pl-pds">"</span></span>&gt;
    &lt;<span class="pl-ent">img</span> <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>u-block<span class="pl-pds">"</span></span> <span class="pl-e">src</span>=<span class="pl-s"><span class="pl-pds">"</span>{{src}}<span class="pl-pds">"</span></span> <span class="pl-e">alt</span>=<span class="pl-s"><span class="pl-pds">"</span><span class="pl-pds">"</span></span>&gt;
  &lt;/<span class="pl-ent">a</span>&gt;
  &lt;<span class="pl-ent">p</span> <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>u-sizeFill u-textBreak<span class="pl-pds">"</span></span>&gt;
    …
  &lt;/<span class="pl-ent">p</span>&gt;
&lt;/<span class="pl-ent">div</span>&gt;</pre></div>

<h3>
<a id="user-content-responsive-utilities" class="anchor" href="#responsive-utilities" aria-hidden="true"><span class="octicon octicon-link"/></a>Responsive utilities</h3>

<p>Certain utilities have responsive variants using the patterns: <code>u-sm-&lt;name&gt;</code>,
<code>u-md-&lt;name&gt;</code>, and <code>u-lg-&lt;name&gt;</code> for small, medium, and large Media Query
breakpoints.</p>



<p>The CSS responsible for component-specific styling.</p>

<p>Syntax: <code>[&lt;namespace&gt;-]&lt;ComponentName&gt;[--modifierName|-descendentName]</code></p>

<p>This has several benefits when reading and writing HTML and CSS:</p>

<ul class="task-list">
<li>It helps to distinguish between the classes for the root of the component,
descendent elements, and modifications.</li>
<li>It keeps the specificity of selectors low.</li>
<li>It helps to decouple presentation semantics from document semantics.</li>
</ul>

<h3>
<a id="user-content-namespace-optional" class="anchor" href="#namespace-optional" aria-hidden="true"><span class="octicon octicon-link"/></a>namespace (optional)</h3>

<p>If necessary, components can be prefixed with a namespace. For example, you may
wish to avoid the potential for collisions between libraries and your custom
components by prefixing all your components with a namespace.</p>

<div class="highlight highlight-css"><pre><span class="pl-e">.twt-Button</span> { <span class="pl-c">/* … */</span> }
<span class="pl-e">.twt-Tabs</span> { <span class="pl-c">/* … */</span> }</pre></div>

<p>This makes it clear, when reading the HTML, which components are part of your
library.</p>

<h3>
<a id="user-content-componentname" class="anchor" href="#componentname" aria-hidden="true"><span class="octicon octicon-link"/></a>ComponentName</h3>

<p>The component's name must be written in pascal case. Nothing else in the
HTML/CSS uses pascal case.</p>



<div class="highlight highlight-html"><pre>&lt;<span class="pl-ent">article</span> <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>MyComponent<span class="pl-pds">"</span></span>&gt;
  …
&lt;/<span class="pl-ent">article</span>&gt;</pre></div>

<h3>
<a id="user-content-componentname--modifiername" class="anchor" href="#componentname--modifiername" aria-hidden="true"><span class="octicon octicon-link"/></a>ComponentName--modifierName</h3>

<p>A component modifier is a class that modifies the presentation of the base
component in some form (e.g., for a certain configuration of the component).
Modifier names must be written in camel case and be separated from the
component name by two hyphens. The class should be included in the HTML <em>in
addition</em> to the base component class.</p>

<div class="highlight highlight-css"><pre><span class="pl-c">/* Core button */</span>
<span class="pl-e">.Button</span> { <span class="pl-c">/* … */</span> }
<span class="pl-c">/* Default button style */</span>
<span class="pl-e">.Button--default</span> { <span class="pl-c">/* … */</span> }</pre></div>

<div class="highlight highlight-html"><pre>&lt;<span class="pl-ent">button</span> <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>Button Button--default<span class="pl-pds">"</span></span> <span class="pl-e">type</span>=<span class="pl-s"><span class="pl-pds">"</span>button<span class="pl-pds">"</span></span>&gt;…&lt;/<span class="pl-ent">button</span>&gt;</pre></div>

<h3>
<a id="user-content-componentname-descendentname" class="anchor" href="#componentname-descendentname" aria-hidden="true"><span class="octicon octicon-link"/></a>ComponentName-descendentName</h3>

<p>A component descendent is a class that is attached to a descendent node of a
component. It's responsible for applying presentation directly to the
descendent on behalf of a particular component. Descendent names must be
written in camel case.</p>

<div class="highlight highlight-html"><pre>&lt;<span class="pl-ent">article</span> <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>Tweet<span class="pl-pds">"</span></span>&gt;
  &lt;<span class="pl-ent">header</span> <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>Tweet-header<span class="pl-pds">"</span></span>&gt;
    &lt;<span class="pl-ent">img</span> <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>Tweet-avatar<span class="pl-pds">"</span></span> <span class="pl-e">src</span>=<span class="pl-s"><span class="pl-pds">"</span>{{src}}<span class="pl-pds">"</span></span> <span class="pl-e">alt</span>=<span class="pl-s"><span class="pl-pds">"</span>{{alt}}<span class="pl-pds">"</span></span>&gt;
    …
  &lt;/<span class="pl-ent">header</span>&gt;
  &lt;<span class="pl-ent">div</span> <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>Tweet-bodyText<span class="pl-pds">"</span></span>&gt;
    …
  &lt;/<span class="pl-ent">div</span>&gt;
&lt;/<span class="pl-ent">article</span>&gt;</pre></div>

<h3>
<a id="user-content-componentnameis-stateofcomponent" class="anchor" href="#componentnameis-stateofcomponent" aria-hidden="true"><span class="octicon octicon-link"/></a>ComponentName.is-stateOfComponent</h3>

<p>Use <code>is-stateName</code> to reflect changes to a component's state. The state name
must be camel case. <strong>Never style these classes directly; they should always be
used as an adjoining class.</strong></p>

<p>This means that the same state names can be used in multiple contexts, but
every component must define its own styles for the state (as they are scoped to
the component).</p>

<div class="highlight highlight-css"><pre><span class="pl-e">.Tweet</span> { <span class="pl-c">/* … */</span> }
<span class="pl-e">.Tweet.is-expanded</span> { <span class="pl-c">/* … */</span> }</pre></div>

<div class="highlight highlight-html"><pre>&lt;<span class="pl-ent">article</span> <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>Tweet is-expanded<span class="pl-pds">"</span></span>&gt;
  …
&lt;/<span class="pl-ent">article</span>&gt;</pre></div>
</article>
