Menu
Guides
Storefront Development

Storefront Development

Styling a section

Use FastStore utilities and custom Sass mixins to create reusable styles for storefront sections.

3 min read
FastStore sections support Sass mixins, which let you reuse style groups. This guide shows how to style a custom section with FastStore utility mixins and how to share a custom mixin across sections.

Before you begin

Using FastStore mixins in a section

The FastStore utility stylesheet provides mixins for layout, spacing, responsive breakpoints, text truncation, and focus states. Import this stylesheet with the Sass @use rule in every SCSS file that uses its mixins.
The following example styles a PromoBanner section.
  1. Create src/components/PromoBanner/section.module.scss and import the FastStore utilities. The as u clause assigns them the u namespace, which is used in each @include.
    src/components/PromoBanner/section.module.scss

    _26
    @use "@faststore/ui/src/styles/base/utilities" as u;
    _26
    _26
    @layer components {
    _26
    .section {
    _26
    @include u.layout-content;
    _26
    _26
    display: grid;
    _26
    gap: var(--fs-spacing-3);
    _26
    padding-block: var(--fs-spacing-5);
    _26
    padding-inline: var(--fs-spacing-3);
    _26
    background-color: var(--fs-color-neutral-bkg);
    _26
    _26
    @include u.media(">=tablet") {
    _26
    grid-template-columns: 2fr 1fr;
    _26
    align-items: center;
    _26
    padding-inline: var(--fs-spacing-5);
    _26
    }
    _26
    }
    _26
    _26
    .title {
    _26
    @include u.truncate-title(2);
    _26
    _26
    margin: 0;
    _26
    font-size: var(--fs-text-size-title-section);
    _26
    }
    _26
    }

    In this example:
    • layout-content limits the section to the store content width and centers it.
    • media(">=tablet") applies styles at the tablet breakpoint and above.
    • truncate-title(2) limits the title to two lines.
    • FastStore global tokens provide consistent spacing, color, and typography values.
    • @layer components places the styles in the FastStore component layer so they follow the expected cascade order.
  2. Import the stylesheet in the section component and apply its classes to the corresponding elements.
    src/components/PromoBanner/PromoBanner.tsx

    _15
    import styles from "./section.module.scss";
    _15
    _15
    interface PromoBannerProps {
    _15
    title: string;
    _15
    description: string;
    _15
    }
    _15
    _15
    export default function PromoBanner({ title, description }: PromoBannerProps) {
    _15
    return (
    _15
    <section className={styles.section}>
    _15
    <h2 className={styles.title}>{title}</h2>
    _15
    <p>{description}</p>
    _15
    </section>
    _15
    );
    _15
    }

  3. Run your FastStore project locally and open a page that contains the section. The section uses a single-column layout on smaller screens and changes to two columns at the tablet breakpoint.
{"base64":"  ","img":{"width":1280,"height":720,"type":"jpg","mime":"image/jpeg","wUnits":"px","hUnits":"px","length":95285,"url":"https://cdn.jsdelivr.net/gh/vtexdocs/dev-portal-content@main/images/faststore-promo-banner-result.jpg"}}

Creating a reusable mixin

For styles shared by multiple custom sections, create a Sass module in your project and explicitly load it in each section stylesheet.
  1. Create src/styles/_section-mixins.scss:
    src/styles/_section-mixins.scss

    _11
    @use "@faststore/ui/src/styles/base/utilities" as u;
    _11
    _11
    @mixin highlighted-section($background: var(--fs-color-highlighted-bkg)) {
    _11
    @include u.layout-colored(
    _11
    $background,
    _11
    var(--fs-spacing-4),
    _11
    var(--fs-spacing-4)
    _11
    );
    _11
    _11
    border-radius: var(--fs-border-radius);
    _11
    }

  2. Import the module into the section stylesheet and include the mixin:
    src/components/PromoBanner/section.module.scss

    _10
    @use "@faststore/ui/src/styles/base/utilities" as u;
    _10
    @use "../../styles/section-mixins" as sectionMixins;
    _10
    _10
    @layer components {
    _10
    .section {
    _10
    @include u.layout-content;
    _10
    @include sectionMixins.highlighted-section;
    _10
    }
    _10
    }

The leading underscore in _section-mixins.scss marks the file as a Sass partial. Omit the underscore and the file extension in the @use path.

Available FastStore utilities

The utility stylesheet includes:
CategoryUtilities
Layout and spacinglayout-content, layout-content-full, layout-colored, and section-divisor
Responsive stylesmedia, with the phone, phonemid, tablet, notebook, and desktop breakpoints
Texttruncate-title
Focus statesinput-focus-ring, focus-ring, and focus-ring-visible
Unit conversionrem function
All FastStore utilities use a namespace. For example:

_10
@use "@faststore/ui/src/styles/base/utilities" as u;
_10
_10
.example {
_10
font-size: u.rem(18px);
_10
_10
@include u.media("<notebook") {
_10
@include u.layout-content;
_10
}
_10
}

Best practices

  • Utility mixins are not global in FastStore v4. Each SCSS file that uses them must load the utility stylesheet with @use.
  • A src/styles/custom-mixins.scss file isn't automatically loaded into section styles. Import project mixins explicitly in every file where you use them.
  • Sass mixins run when the storefront CSS is built. They can't be selected or configured by content editors in Headless CMS. To make a style configurable in the CMS, expose a section property and map its value to a class or data attribute in the component.
  • Use design tokens when you only need to change a component's colors, spacing, typography, or other theme values. Use mixins for reusable groups of style declarations.