Apply styling to the core components
How do I write styles?
There are two methods that we recommend to style our core components.
The simple method uses the global CSS variables for global styling across all core components. These variables are simple to change and are applied across all components. They are, however, more limited in what they can do. You can change basic colors and have limited control over the font and font sizes used. Styling your components using these variables has the advantage that newly released components will inherit these color configurations automatically when new components are released.
The advanced method is by overriding an individual component’s CSS. This allows finer control of what you can change but requires greater knowledge of web development and needs to be written for each component.
Simple method
We have configured our components CSS to allow overriding some basic styling via CSS variables These variable allow you to set a basic starting colours which all components will make use of in some way, not all components make use of all variables but most do in some way.
To find out what variables effect what in a component you can experiment by changing the values and observing what effect it has on the page or you can make use of your browsers development mode to inspect the elements of the page and determine if they are deriving a value from a specific CSS variable or not.
Global fonts
You can control the basic font sizes used or the primary font for most components. The styles below values are the general defaults used across all components. These can be changed to allow you to set a smaller or larger font size, or an alternative font family to use.
--sq-component-font-family: 'IBM Plex Sans', 'Arial', sans-serif;
--sq-component-font-size: 1rem;
--sq-component-font-weight: 400;
--sq-component-line-height: 1.5;
Styles for all components
Most components inherit styles from a set of global css variables. For example, the color used for links. These variables must use a valid CSS colour name or a valid colour hex value. For example:
-
white
; or -
#ffffff
.
/* Component default color */
--sq-component-default-color: #262626;
--sq-component-default-bg-color: #fff;
/* Component primary color */
--sq-component-primary-color: #262626;
--sq-component-primary-bg-color: #f4f4f4;
/* Component secondary color */
--sq-component-secondary-color: #fff;
--sq-component-secondary-bg-color: #606060;
/* Button */
--sq-btn-font-size: 1rem;
--sq-btn-font-weight: 400;
--sq-btn-line-height: 1.5;
--sq-btn-border-radius: 0;
/* Heading */
--sq-component-heading-font-family: 'IBM Plex Sans', 'Arial', sans-serif;
--sq-component-heading-font-size: 2rem;
--sq-component-heading-font-weight: 700;
--sq-component-heading-line-height: 1.375;
/* Heading default color */
--sq-component-heading-default-color: #262626;
/* Heading primary color */
--sq-component-heading-primary-color: #262626;
/* Heading primary color */
--sq-component-heading-secondary-color: #fff;
Styles for specific components
Most components inherit styles from a set of global rules. For example, the color used for links. These variables must use a valid CSS colour name or a valid colour hex value. For example:
-
white
; or -
#ffffff
.
pull quote
component./* Pull quote */
--pull-quote-body-font-family: var(
--sq-component-font-family,
'IBM Plex Sans',
'Arial',
sans-serif
);
--pull-quote-body-font-size: var(--sq-component-font-size, 1rem);
--pull-quote-body-font-weight: var(--sq-component-font-weight, 200);
--pull-quote-body-line-height: var(--sq-component-line-height, 1.375);
--pull-quote-dark-color: #606060;
--pull-quote-body-color: var(--sq-component-default-color, #262626);
--pull-quote-body-bg-color: var(--sq-component-default-bg-color, #fff);
--pull-quote-author-font-family: 'IBM Plex Sans', 'Arial', sans-serif;
--pull-quote-author-font-size: 1.25rem;
--pull-quote-quote-font-size: 2rem;
--pull-quote-author-font-weight: 400;
--pull-quote-author-line-height: 1.3;
--pull-quote-quote-line-height: 1.375;
--pull-quote-author-color: #606060;
--pull-quote-author-bg-color: #fff;
Advanced method
Squiz core components use standard CSS and the BEM methodology to control how each component is presented to the user.
Styling components using BEM (Block Element Modifier) involves naming CSS classes with a specific structure that clearly
identifies a component as a block
, its internal parts as elements
, and any variations of the component as modifiers
allowing for highly organized and reusable styles within your project by clearly defining the relationships between
different parts of a component.
Key points about BEM:
Naming convention: Class names follow the pattern: block__element—modifier
.
Block: Represents the main component itself, like a "header" or "button."
Element: A part of the block, like a "title" within a "header" or an "icon" within a "button."
Modifier: A flag that changes the appearance of a block or element, like "large" or "active".
<div class="card">
<h2 class="card__title">Product Name</h2>
<p class="card__description">A detailed description of the product.</p>
<button class="card__button--primary">Add to Cart</button>
</div>
where:
card
: The block, representing the entire card component.
card__title
: An element within the card, specifically the title.
card__button—primary
: A button element within the card, with a "primary" modifier class.
To make changes to the presentation of each component, simply add new rules where the selector targets the component you wish to change.