---
title: "Code Blocks"
description: "Learn how to manage, format, and highlight code blocks with Contentstack's JSON Rich Text Editor. Improve readability and structure technical content effortlessly."
url: "https://www.contentstack.com/docs/headless-cms/code-blocks"
product: "Contentstack"
doc_type: "guide"
audience:
  - developers
  - admins
version: "current"
last_updated: "2026-07-23"
---

# 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:

1.  Navigate to the desired [stack](/docs/headless-cms/about-stack), then click the **Entries** icon.
2.  Create a new entry or open an existing one containing a JSON RTE field.
3.  Select the relevant content, click the **Format** icon in the toolbar, and select **Code Snippet** from the dropdown menu.
4.  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:

1.  Click the inserted **code block** in the JSON RTE.
2.  Select a programming language from the dropdown menu.
3.  To move to the next line within the code block, press **Enter**.
4.  To exit the code block, press **Shift + Enter**.
    
    ![Apply syntax highlighting to code blocks](https://images.contentstack.io/v3/assets/blt2d43f51baca745a8/blt5cfcc4a2f42fed51/6819cbf1ae96e76c5ed39731/1-apply-language-formatting-to-c.gif "image_tooltip")
    

## 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.