# Limit the CSS Units Offered in the Editor

> Reduces the unit dropdowns in spacing and size controls to the units you want (for example px, rem and %), keeping layouts consistent.

- Type: PHP
- Runs: Run everywhere
- Category: [Block Editor](https://wpide.com/library/category/gutenberg/)
- Tags: theme-json, units, block-editor
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/themejson-allowed-units/

## Code

```php
// Units offered in spacing, width and height controls.
$wpide_units = array( 'px', 'rem', '%', 'vw' );

add_filter( 'wp_theme_json_data_theme', function ( $theme_json ) use ( $wpide_units ) {
    return $theme_json->update_with( array(
        'version'  => WP_Theme_JSON::LATEST_SCHEMA,
        'settings' => array( 'spacing' => array( 'units' => array_values( $wpide_units ) ) ),
    ) );
} );
```

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Limit the CSS Units Offered in the Editor" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
