Code

Display code snippets that respect your spacing and tabs.

This block is available in the latest version of WordPress and does not require the Gutenberg plugin.

Category:

For developers

Block Grammar & Markup

<!-- wp:core/code -->
<pre class="wp-block-code"><code>export default function MyButton() {
	return <Button>Click Me!</Button>;
}</code></pre>
<!-- /wp:core/code -->

Block Attributes

Optional. Type: Object.

Attributes provide the structured data needs of a block. They can exist in different forms when they are serialized, but they are declared together under a common interface.

Documentation

{
  "content": {
    "type": "string",
    "source": "html",
    "selector": "code"
  },
  "anchor": {
    "type": "string",
    "source": "attribute",
    "attribute": "id",
    "selector": "*"
  }
}

Block Supports

Optional. Type: Object.

A set of options that enables or disables block controls in the editor, for example gradient colors or padding.

Documentation

{
  "anchor": true,
  "typography": {
    "fontSize": true,
    "lineHeight": true,
    "__experimentalFontFamily": true,
    "__experimentalFontWeight": true,
    "__experimentalFontStyle": true,
    "__experimentalTextTransform": true,
    "__experimentalTextDecoration": true,
    "__experimentalLetterSpacing": true,
    "__experimentalDefaultControls": {
      "fontSize": true
    }
  },
  "spacing": {
    "margin": [
      "top",
      "bottom"
    ],
    "padding": true
  },
  "__experimentalBorder": {
    "radius": true,
    "color": true,
    "width": true,
    "style": true,
    "__experimentalDefaultControls": {
      "width": true,
      "color": true
    }
  },
  "color": {
    "text": true,
    "background": true,
    "gradients": true,
    "__experimentalDefaultControls": {
      "background": true,
      "text": true
    }
  }
}

Transforms

Optional. Type: Object.

Transforms provide rules for what a block can be transformed from and what it can be transformed to.

Documentation

Transforms from: Html, paragraph.

Transforms to: Paragraph.