How to make component library styles work correctly inside the WordPress block editor.
The block editor uses an iframe. Styles must be explicitly loaded inside it — stylesheets on the parent page do not reach block content in the editor.
integrate.php handles token loading automatically. It enqueues the token CSS on both wp_enqueue_scripts (frontend) and enqueue_block_editor_assets (editor iframe). No additional setup needed.
Add editorStyle to your block.json alongside style:
{
"style": ["mylib-card"],
"editorStyle": ["mylib-card"]
}Using the same handle for both means the component renders identically in both contexts.
If components need adjustments inside the editor (different max-width, pointer events, or spacing for editor chrome):
/* editor.css */
.editor-styles-wrapper .mylib-card {
max-width: 100%;
}Register and associate the editor override stylesheet:
wp_register_style(
'mylib-card-editor',
$plugin_uri . 'assets/css/editor/card-editor.css',
[ 'mylib-card' ],
'0.0.1'
);{
"style": ["mylib-card"],
"editorStyle": ["mylib-card", "mylib-card-editor"]
}The editor override loads after the component CSS (via the dependency) and only in the editor context.
- Check
editorStylein block.json — without it, the editor iframe won't load the CSS - Verify
integrate.phpis loaded — it enqueues tokens onenqueue_block_editor_assets - Inspect the editor iframe's
<head>to see which stylesheets are loaded - Verify the style handle is registered —
editorStylereferences the same handle fromwp_register_style
- Check for editor wrapper specificity —
.editor-styles-wrapperparent can affect styles - Check for missing editor overrides — some components need adjustments for editor context
- Inspect the editor iframe — compare computed styles between editor and frontend