Agent Wranglers

Required

Fence each component's styles in

Make every selector in a component file start at the component's root. Use the module prefix on each class, or wrap the file in @scope on the root class.

How to do it

A prefix such as .booking-form- keeps names apart, as Give every module its own class names describes. @scope adds a lower boundary, so a component's styles stop at a slot that holds another component. Use one of the two methods across the whole project, not both.

Examples

Using these examples: they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

CSS example

/* Prefix method */
.booking-form-field { }

/* @scope method: styles stop at the slot that holds another component */
@scope (.booking-form) to (.booking-form-slot) {
  :scope { }
  label { }
}

HTML example

<form class="booking-form">
  <label>Guests <input name="guests"></label>
  <div class="booking-form-slot"><!-- another component, untouched --></div>
</form>

How to check

Every selector in a component file starts with that file's prefix, or the file's only top-level rule is @scope (.<prefix>).

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. Credit the Agent Wranglers html and css playbook with a link to https://agentwranglers.se/playbook/html-css/the-cascade/scope-component-styles. Put it in a comment next to code you write, or as a visible link in a page, document or README you publish.