Title: wp_enqueue_block_style
Published: February 3, 2022
Last modified: May 20, 2026

---

# wp_enqueue_block_style( string $block_name,  $args )

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/?output_format=md#wp--skip-link--target)

Enqueues a stylesheet for a specific block.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/?output_format=md#description)󠁿

If the theme has opted-in to load block styles on demand, then the stylesheet will
be enqueued on-render, otherwise when the block inits.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/?output_format=md#parameters)󠁿

 `$block_name`stringrequired

The block-name, including namespace.

`string|string[]|bool|null`> $args { An array of arguments. See [wp_register_style()](https://developer.wordpress.org/reference/functions/wp_register_style/)
for full information about each argument.
 @type string $handle The handle for the
stylesheet. @type `string|false` $src The source URL of the stylesheet. @type string[]
$deps Array of registered stylesheet handles this stylesheet depends on. @type `
string|bool|null` $ver Stylesheet version number. @type string $media The media 
for which this stylesheet has been defined. @type `string|null` $path Absolute path
to the stylesheet, so that it can potentially be inlined. }

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/?output_format=md#source)󠁿

    ```php
    function wp_enqueue_block_style( $block_name, $args ) {
    	$args = wp_parse_args(
    		$args,
    		array(
    			'handle' => '',
    			'src'    => '',
    			'deps'   => array(),
    			'ver'    => false,
    			'media'  => 'all',
    		)
    	);

    	/**
    	 * Callback function to register and enqueue styles.
    	 *
    	 * @param string $content When the callback is used for the render_block filter,
    	 *                        the content needs to be returned so the function parameter
    	 *                        is to ensure the content exists.
    	 * @return string Block content.
    	 */
    	$callback = static function ( $content ) use ( $args ) {
    		// Register the stylesheet.
    		if ( ! empty( $args['src'] ) ) {
    			wp_register_style( $args['handle'], $args['src'], $args['deps'], $args['ver'], $args['media'] );
    		}

    		// Add `path` data if provided.
    		if ( isset( $args['path'] ) ) {
    			wp_style_add_data( $args['handle'], 'path', $args['path'] );

    			// Get the RTL file path.
    			$rtl_file_path = str_replace( '.css', '-rtl.css', $args['path'] );

    			// Add RTL stylesheet.
    			if ( file_exists( $rtl_file_path ) ) {
    				wp_style_add_data( $args['handle'], 'rtl', 'replace' );

    				if ( is_rtl() ) {
    					wp_style_add_data( $args['handle'], 'path', $rtl_file_path );
    				}
    			}
    		}

    		// Enqueue the stylesheet.
    		wp_enqueue_style( $args['handle'] );

    		return $content;
    	};

    	$hook = did_action( 'wp_enqueue_scripts' ) ? 'wp_footer' : 'wp_enqueue_scripts';
    	if ( wp_should_load_block_assets_on_demand() ) {
    		/**
    		 * Callback function to register and enqueue styles.
    		 *
    		 * @param string $content The block content.
    		 * @param array  $block   The full block, including name and attributes.
    		 * @return string Block content.
    		 */
    		$callback_separate = static function ( $content, $block ) use ( $block_name, $callback ) {
    			if ( ! empty( $block['blockName'] ) && $block_name === $block['blockName'] ) {
    				return $callback( $content );
    			}
    			return $content;
    		};

    		/*
    		 * The filter's callback here is an anonymous function because
    		 * using a named function in this case is not possible.
    		 *
    		 * The function cannot be unhooked, however, users are still able
    		 * to dequeue the stylesheets registered/enqueued by the callback
    		 * which is why in this case, using an anonymous function
    		 * was deemed acceptable.
    		 */
    		add_filter( 'render_block', $callback_separate, 10, 2 );
    		return;
    	}

    	/*
    	 * The filter's callback here is an anonymous function because
    	 * using a named function in this case is not possible.
    	 *
    	 * The function cannot be unhooked, however, users are still able
    	 * to dequeue the stylesheets registered/enqueued by the callback
    	 * which is why in this case, using an anonymous function
    	 * was deemed acceptable.
    	 */
    	add_filter( $hook, $callback );

    	// Enqueue assets in the editor.
    	add_action( 'enqueue_block_assets', $callback );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/script-loader.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/script-loader.php#L3376)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/script-loader.php#L3376-L3467)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_should_load_block_assets_on_demand()](https://developer.wordpress.org/reference/functions/wp_should_load_block_assets_on_demand/)`wp-includes/script-loader.php` |

Checks whether block styles should be loaded only on-render.

  | 
| [is_rtl()](https://developer.wordpress.org/reference/functions/is_rtl/)`wp-includes/l10n.php` |

Determines whether the current locale is right-to-left (RTL).

  | 
| [wp_register_style()](https://developer.wordpress.org/reference/functions/wp_register_style/)`wp-includes/functions.wp-styles.php` |

Registers a CSS stylesheet.

  | 
| [wp_style_add_data()](https://developer.wordpress.org/reference/functions/wp_style_add_data/)`wp-includes/functions.wp-styles.php` |

Adds metadata to a CSS stylesheet.

  | 
| [did_action()](https://developer.wordpress.org/reference/functions/did_action/)`wp-includes/plugin.php` |

Retrieves the number of times an action has been fired during the current request.

  | 
| [wp_parse_args()](https://developer.wordpress.org/reference/functions/wp_parse_args/)`wp-includes/functions.php` |

Merges user defined arguments into defaults array.

  | 
| [wp_enqueue_style()](https://developer.wordpress.org/reference/functions/wp_enqueue_style/)`wp-includes/functions.wp-styles.php` |

Enqueues a CSS stylesheet.

  | 
| [add_filter()](https://developer.wordpress.org/reference/functions/add_filter/)`wp-includes/plugin.php` |

Adds a callback function to a filter hook.

  | 
| [add_action()](https://developer.wordpress.org/reference/functions/add_action/)`wp-includes/plugin.php` |

Adds a callback function to an action hook.

  |

[Show 4 more](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/?output_format=md#comment-content-5788)
 2.    [abditsori](https://profiles.wordpress.org/abditsori/)  [  4 years ago  ](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/#comment-5788)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_enqueue_block_style%2F%23comment-5788)
     Vote results for this note: 6[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_enqueue_block_style%2F%23comment-5788)
 4.  Following the standard approach, you can enqueue your block custom styles iteratively
     like this. Place your block custom style sheet in /assets/css/blocks/ directory.
     For example, if you want to override the Post Author block Avatar and content 
     style, create /assets/css/blocks/post-author.css and add your custom styles for
     the respective classes there. After that, add the following snippet to your `after_setup_theme`
     callback function which is, `twentytwentytwo_support()` in this example.
 5.      ```php
         function twentytwentytwo_support() {
         			/*
         			 * Load additional block styles.
         			 */
         			    $styled_blocks = ['post-author'];
         			foreach ( $styled_blocks as $block_name ) {
         				$args = array(
         					'handle' => "twentytwentytwo-$block_name",
         					'src'    => get_theme_file_uri( "assets/css/blocks/$block_name.css" ),
         				);
         				wp_enqueue_block_style( "core/$block_name", $args );
         			}
         		}
         ```
     
 6.  Finally, include this in your functions.php file.
 7.      ```php
         add_action( 'after_setup_theme', 'twentytwentytwo_support' );
         ```
     
 8.  post-author.css for your reference, I would like the avatar to be round and the
     Author name centered inline with the Avatar.
 9.  .wp-block-post-author__avatar img {
      border-radius: 50%; }
 10. .wp-block-post-author__name {
      line-height: 2.5em; }
 11.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_enqueue_block_style%2F%3Freplytocom%3D5788%23feedback-editor-5788)
 12.  [Skip to note 5 content](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/?output_format=md#comment-content-6261)
 13.   [Lovro Hrust](https://profiles.wordpress.org/lovor/)  [  3 years ago  ](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/#comment-6261)
 14. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_enqueue_block_style%2F%23comment-6261)
     Vote results for this note: 2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_enqueue_block_style%2F%23comment-6261)
 15. This function can be called directly, without hooking it to specific action, because
     it hooks enqueuing internally to `enqueue_block_assets`. If it is hooked to the
     same hook, it will not work.
 16.  * However, if you want to load block css optimally, only if block is present 
        on page, you should use `add_filter( 'should_load_separate_core_block_assets','
        __return_true' );` in functions.php or plugin if you call `wp_enqueue_block_style()`
        without hook. This setting should happen automatically if you are using FSE,
        but adding this filter to true happens in theme.php which is called after enqueueing
        starts. Alternatively, use `after_setup_theme` hook to call this function, 
        like in the example from abditsori.
      * [Lovro Hrust](https://profiles.wordpress.org/lovor/) [2 years ago](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/#comment-7172)
      * add_action( ‘after_setup_theme’, ‘twentytwentytwo_support’ );
      * [jjgliss83](https://profiles.wordpress.org/jjgliss83/) [2 years ago](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/#comment-7232)
 17.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_enqueue_block_style%2F%3Freplytocom%3D6261%23feedback-editor-6261)
 18.  [Skip to note 6 content](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/?output_format=md#comment-content-7236)
 19.   [Lovro Hrust](https://profiles.wordpress.org/lovor/)  [  2 years ago  ](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/#comment-7236)
 20. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_enqueue_block_style%2F%23comment-7236)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_enqueue_block_style%2F%23comment-7236)
 21. If your block is called ‘namespace/name’, do not set handle argument to ‘namespace-
     name-style’, because that style is already used by the WordPress to enqueue block
     styles and style will not be enqueued.
 22.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_enqueue_block_style%2F%3Freplytocom%3D7236%23feedback-editor-7236)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_enqueue_block_style%2F)
before being able to contribute a note or feedback.