Resolve an SCSS theme partial and check its CSS in a page
Admin ·
Before moving a Sass snippet to a project, check that its partial resolves and that the resulting selector targets the element you intend. This example uses a theme partial and a direct-child caption selector.
Compile the two-file theme example
Load the example and leave Output style on Expanded. The main file begins with @use "theme/tokens". The inline file theme/_tokens.scss defines the accent as #246851 and the spacing as 6px.
Select Compile CSS. Sass flattens the nested selector to .field-card > .caption and computes its padding as 12px. The .field-card rule keeps a 2px solid border using the theme accent.
.field-card {
border: 2px solid #246851;
}
.field-card > .caption {
padding: 12px;
}Trace a missing partial to the @use line
Rename the inline file to theme/_colors.scss and compile again. The compiler points to the @use statement because theme/tokens no longer resolves. Change the filename back and compile again.
The underscore marks a Sass partial. Specify the logical module path in @use, and retain its directory and filename as the supplied inline path. The browser workspace resolves its inline source without reading your project filesystem.
Verify expanded and compressed CSS in your page
Download compiled.css and use it with a field-card element that directly contains a caption element. In the browser's computed styles, check a 2px border and 12px caption padding. A deeper caption inside another wrapper misses the direct-child selector.
Choose Compressed and compile the same input again. Recheck the computed values. Formatting and color notation can differ between the files while the browser applies the same declarations.
Sass parent selectorDart Sass compileString and output options
Common questions
Do I need the .scss suffix or the underscore in @use?
Sass can locate a partial with a leading underscore and infer the .scss suffix. The inline path is theme/_tokens.scss and the @use path is theme/tokens in this example.
Will a CSS url() be loaded during compilation?
Compilation can preserve a CSS URL as text. The browser may resolve that URL later if you add the compiled stylesheet to a page.