In my previous blog, I discussed on how we can add basic style and rules in Sitecore XM Cloud Components style library. In the current blog, I’ll discuss on how to apply rules to the elements and how to implement theme.
Applying Style Rules to Elements in XM Cloud Components
Once you have added the basic styles (colors, fonts, graphics, and breakpoints) to your Styles library and bundled them into style rules, you must specify which style rules can be applied to specific elements. This ensures that only on-brand and curated style options are available in the Styles library, which will be used in the Components builder. Custom CSS styles can also be added to elements for greater flexibility.
Add a Text Element Style
Text elements come with six default collections: Heading 1, Heading 2, Heading 3, Heading 4, Heading 5, and Paragraph. Each text element is automatically assigned the corresponding HTML tag (e.g., adding a text element from the Heading 1 collection assigns an <h1>
tag).
To add a text element style:
- In the Styles builder, click Text elements in the left pane.
- Click Add style (+ icon) for the type of text element you want to add.
- Enter a name for the text element.
- On the Typography and Color tabs, select the styles you want available for this text element.
- Optionally, add custom CSS in the Custom CSS tab.
- Click Save.
Add an Inline Element Style
Inline elements include links, buttons, and badges.
To add a style to an inline element:
- In the Styles builder, click Inline elements in the left pane.
- Scroll to the type of inline element you want to style.
- Click Add style.
- Enter a name and optionally a description for the style.
- On the Typography, Spacing, Decoration, Fill, and Text color tabs, select only the styles you want for the inline element.
- Optionally, add custom CSS in the Custom CSS tab.
- Click Save.
Add a Block Element Style
Block elements include sections, cards, block quotes, and image blocks. Sections are typically top-level blocks (like full-width panels), while cards are nestable boxes within sections that frame content visually.
To add a style to a section or card:
- In the Styles builder, click Block elements in the left pane.
- Scroll to the element type you want to style.
- Click Add style.
- Enter a name for your block element.
- On the Fill, Decoration, and Spacing tabs, select only the styles you want to apply to this block element.
- Optionally, add custom CSS in the Custom CSS tab.
- Click Save.
Create Custom Inline and Block Elements
By default, inline elements come with Buttons, Badges, and Links collections, while block elements come with Sections and Cards collections. You can also create custom inline or block elements tailored to your project.
To create a custom block or inline element:
- In the Styles builder, click Add custom type in the top-right corner.
- Enter a name for your custom element.
- Click Save.
Themes in XM Cloud Components
Creating themes is the final step in building an atomic styles library within XM Cloud Components. Themes are composed of a combination of elements and style rules you’ve already defined. Their purpose is to streamline the styling process by allowing multiple styles to be applied at once—for example, applying a light section, dark card, and light text block with a single click.
How to Add a Theme
- In the Styles builder, click Themes in the left pane.
- Click Add theme.
- Enter a name for your theme.
- Navigate to the Block elements, Inline elements, and Text elements tabs.
- For each tab, add the appropriate styles for the various elements.
- For example, in the Block elements tab, click Add section to add a style for sections, and select the desired rules from the drop-down menu.
- You can assign multiple styles to each element. If you assign more than one style, choose a default style for the element.
- Click Save to add the theme to the Styles library.