bricks_create_global_class
Overview
Creates a single global CSS class in the Bricks design system. Define the class name, CSS settings (typography, background, border, spacing, etc.), and optional selectors for interactive states like :hover, :focus, ::before, and ::after. Classes are the foundation of maintainable Bricks sites.
Every content element (heading, text, button, image, icon-box) must reference at least one global class. This tool creates the reusable styles that prevent inline styling across the site. For creating 3 or more classes at once, prefer bricks_create_classes_batch for better performance.
Key Features
When to Use
When you need a single new class with specific hover/focus selectors
When a "Global Class Warning" indicates missing classes on content elements
When you need to create a class with complex pseudo-element selectors (::before, ::after)
When creating 1-2 classes — for 3+ classes use bricks_create_classes_batch instead
When NOT to Use
When a suitable class already exists — use bricks_get_global_classes to check first
When you need to modify an existing class — use bricks_update_global_class instead
Parameters
namestringREQUIREDcategorystringoptionalsettingsobjectREQUIREDselectorsarrayoptionalCode Examples
Create a section label typography class
A reusable class for section subtitle text (uppercase, accent color, letter-spacing). Applied via globalClasses: ["section-label"] on text-basic elements.
// Create a section label class (uppercase, accent color)
bricks_create_global_class({
name: "section-label",
category: "Typography",
settings: {
"_typography": {
"font-size": "14px",
"color": { "raw": "var(--bricks-color-accent)" },
"letter-spacing": "0.7px",
"text-transform": "uppercase",
"text-align": "center",
"font-weight": "600"
},
"_margin": { "bottom": "8" }
}
}){
"id": "a1b2c3",
"name": "section-label",
"message": "Global class 'section-label' created successfully."
}Create a button class with hover effect
A primary button class with background, padding, border-radius, and a hover selector that darkens the color and adds a shadow.
// Create a button class with hover selector
bricks_create_global_class({
name: "btn-primary",
category: "Buttons",
settings: {
"_background": { "color": { "raw": "var(--bricks-color-primary)" } },
"_typography": { "color": { "hex": "#ffffff" }, "font-weight": "600", "font-size": "16px" },
"_padding": { "top": "14", "right": "28", "bottom": "14", "left": "28" },
"_border": { "radius": { "top": "8", "right": "8", "bottom": "8", "left": "8" } },
"_cssTransition": "all 0.3s ease"
},
selectors: [
{
selector: "&:hover",
settings: {
"_background": { "color": { "raw": "var(--bricks-color-primary-dark)" } },
"_transform": "translateY(-2px)",
"_boxShadow": [{ "x": "0", "y": "4", "blur": "12", "spread": "0", "color": { "hex": "#00000020" } }]
}
}
]
}){
"id": "d4e5f6",
"name": "btn-primary",
"message": "Global class 'btn-primary' created successfully."
}Common Mistakes
// WRONG: Inline styles duplicated on every heading
{ "type": "heading", "settings": {
"text": "Our Services", "tag": "h2",
"_typography": { "font-size": "36px", "font-weight": "600", "color": { "hex": "#1a1a2e" } }
}}
// Repeated 10 times across the page — impossible to update globally// RIGHT: Create class ONCE, use everywhere
bricks_create_global_class({
name: "heading-section",
category: "Typography",
settings: {
"_typography": { "font-size": "36px", "font-weight": "600", "color": { "hex": "#1a1a2e" } }
}
})
// Then on every section heading:
{ "type": "heading", "settings": { "text": "Our Services", "tag": "h2" },
"globalClasses": ["heading-section"] }settings: { "_gap": "20px", "_padding": { "top": "32px" } }settings: { "_gap": "20", "_padding": { "top": "32" } }// 10 separate API calls to create 10 utility classes
bricks_create_global_class({ name: "text-sm", ... })
bricks_create_global_class({ name: "text-base", ... })
bricks_create_global_class({ name: "text-lg", ... })
// ... 7 more calls// One batch call for all 10 classes
bricks_create_classes_batch({
classes: [
{ name: "text-sm", settings: { "_typography": { "font-size": "13px" } } },
{ name: "text-base", settings: { "_typography": { "font-size": "16px" } } },
{ name: "text-lg", settings: { "_typography": { "font-size": "20px" } } },
// ... all classes in one call
]
})Tips & Warnings
Critical rule: Every content element (heading, text-basic, button, icon-box, image) MUST reference at least one global class via globalClasses: ["class-name"]. The element settings should contain only content (text, image URL, link), NOT styling.
Recommended classes to create: section-label, heading-section, heading-card, text-body, text-small, btn-primary, btn-secondary, card, card-content, badge, icon-circle. These cover 90%+ of content elements.
Remember: Call bricks_regenerate_assets after creating classes to compile the new CSS into the site stylesheet.