This example demonstrates different techniques for styling WordPress blocks, showcasing best practices for managing CSS in block development. You'll learn how to implement styles using multiple approaches including inline styles, default classes, custom classes, and separate stylesheets for editor and frontend contexts.
Key concepts covered:
- Inline styles through
useBlockProps - Default WordPress block classes (
wp-block-block-development-examples-stylesheets-79a4c3) - Custom class implementation (
hasPerspectivethroughuseBlockProps) - Editor-specific styling (
editor.scss) - Shared frontend/editor styles (
style.scss)
| Example | Description | Tags | Download .zip | Live Demo |
|---|---|---|---|---|
| Stylesheets | Shows different approaches to adding and managing styles in blocks, including editor-specific and front-end styles. | styles featured |
📦 |
- Inline Styles
- Applied directly through
useBlockProps - Provides dynamic styling capabilities
- Applied directly through
- CSS Classes
- Default class:
wp-block-block-development-examples-stylesheets-79a4c3 - Custom class:
hasPerspective(applied conditionally)
- Default class:
The styles are output in several ways:
- Frontend Output
- Block wrapper receives inline styles and classes
- Shared styles loaded via
style.scss - Editor-specific styles isolated in
editor.scss
The inline styles and classes (added via useBlockProps) for the block wrapper are added to the <div> container of the block
The styles shared by the editor and the frontend (style.scss) have been inserted in a style tag
- Block Editor Handbook - Edit and Save
useBlockPropsDocumentation- WordPress Block Styles
- CSS in Gutenberg
Note Check the Start Guide for local development with the examples


