How Block Styles Work
When a user selects a block style:- A className is added to the block wrapper:
is-style-{style-name} - You style this class with CSS
- The user can switch between styles in the block toolbar
Registering Block Styles
JavaScript Registration
UseregisterBlockStyle() to add a style to an existing block:
is-style-fancy-quote class when selected.
PHP Registration
Register styles from PHP usingregister_block_style():
Style Properties
Required Properties
name
The identifier used to compute the CSS class.label
Human-readable label shown in the block toolbar.Style Implementation
Choose one of three methods to provide CSS:1. inline_style
Provide inline CSS directly:2. style_handle
Reference an already-registered stylesheet:3. style_data
Use theme.json-like notation for user-editable styles:style_data, users can modify the style using the Global Styles UI.
Optional Properties
isDefault
Mark a style as the default (no custom class is added):Unregistering Block Styles
JavaScript Unregistration
Wrap in
wp.domReady() and declare wp-edit-post as a dependency to ensure the style is registered before you unregister it.PHP Unregistration
PHP
unregister_block_style() only works with styles registered on the server using register_block_style(). It cannot unregister client-side registered styles.Complete Examples
Example 1: Simple Style with Inline CSS
Example 2: Style with External Stylesheet
PHP:Example 3: Multiple Styles for One Block
Example 4: JavaScript Registration
Block Styles vs Block Variations
Use Block Styles when you only need to change appearance with CSS.
Use Block Variations when you need to:
- Set initial attributes
- Configure inner blocks
- Change block behavior
- Override default values
Combining Styles and Variations
You can use both together:Styling Best Practices
- Use specific selectors: Target the full class path to avoid conflicts
- Respect theme styles: Build on existing block styles rather than overriding everything
- Provide fallbacks: Ensure styles work across different themes
- Test in editor and frontend: Styles should work in both contexts
- Consider color schemes: Support light and dark modes when relevant