---
title: "[JSON RTE] - Code Blocks"
description: How to add and format code blocks in the JSON Rich Text Editor (JSON RTE) in Contentstack, including language formatting and best practices.
url: https://www.contentstack.com/docs/developers/json-rich-text-editor/code-blocks
product: Contentstack
doc_type: guide
audience:
  - developers
version: unknown
last_updated: 2026-03-25
---

# [JSON RTE] - Code Blocks

This page explains how to add code blocks in the Contentstack JSON Rich Text Editor (JSON RTE), apply language-specific formatting (syntax highlighting), and follow best practices. It is intended for developers and content authors creating technical documentation, blogs, or other content that includes formatted code snippets.

## Code Blocks

The JSON RTE in Contentstack offers a powerful way to manage and display rich content, including **formatted code blocks**. This feature is ideal for developers creating technical documentation, blogs, or any content requiring clear, structured code blocks.

To add a code block within your JSON RTE, log in to your
[Contentstack account](https://www.contentstack.com/login/) and perform the steps given below:

- Navigate to the desired [stack](/docs/developers/set-up-stack/about-stack), then click the **Entries** icon in the left navigation panel.
- Create a new entry or open an existing one containing a JSON RTE field.
- Select the relevant content, click the **Format** icon in the toolbar, and select **Code Snippet** from the dropdown menu.
- Alternatively, you can use keyboard shortcut **Cmd + Opt + 8** for Mac users or **Ctrl + Alt + 8** for Windows users.

## Apply Language Formatting to Code Blocks

Contentstack provides built-in syntax highlighting for over **60 programming languages**, including JavaScript, HTML, Python, and more. Follow these steps to apply language-specific formatting:

- Click the inserted **code block** in the JSON RTE.
- Select a programming language from the dropdown menu.
- To move to the next line within the code block, press **Enter**.
- To exit the code block, press **Shift + Enter**.

## Best Practices for Code Blocks

Ensure your code blocks are **readable** and **functional** by following these tips:

- **Use Proper Indentation**: Well-indented code improves readability.
- **Limit Code Length**: For long blocks, **split across multiple blocks** or add comments for clarity.
- **Choose the Right Language**: Use the appropriate **language selector** for accurate syntax highlighting.
- **Test Code Blocks**: Always test the code to ensure it works as intended before adding it to your content.

Using code blocks in the JSON RTE allows developers to effectively manage technical content within Contentstack. Proper formatting ensures code is clear and easy to read, while language-specific syntax highlighting boosts readability and user engagement. Follow the best practices to get the most out of code blocks in your documentation and blogs.

## Common questions

**How do I insert a code block in the JSON RTE?**  
Select the relevant content, click the **Format** icon in the toolbar, and select **Code Snippet** from the dropdown menu, or use **Cmd + Opt + 8** (Mac) / **Ctrl + Alt + 8** (Windows).

**How do I apply syntax highlighting to a code block?**  
Click the inserted **code block** in the JSON RTE and select a programming language from the dropdown menu.

**How do I exit a code block while editing?**  
Press **Shift + Enter** to exit the code block.

**How do I add a new line inside a code block?**  
Press **Enter** to move to the next line within the code block.