Webflow’s native Rich Text element does not support adding code blocks or true preformatted code formatting. By default, it only includes basic formatting options like bold, italic, lists, quotes, and headings.
1. Native Rich Text Limitations
- The Rich Text element in Webflow uses a simplified text model.
- Supported formatting includes Headings 1–6, paragraphs, blockquotes, unordered/ordered lists, and hyperlinks.
- Preformatted text or monospaced code blocks (like
<pre>
or <code>
in HTML) are not available through the native Rich Text Editor.
2. Workarounds to Display Code
To include JSON or other code samples in a visually distinct way, consider the options below:
- Use an Embed element: Add a custom code embed inside a div where you manually write the
<pre><code>{...}</code></pre>
HTML with inline styles or link to external CSS for syntax highlighting. - Convert code to an image: If formatting or scrolling is not needed, you can create a screenshot of the code block and upload it as an image. Not ideal for accessibility or SEO.
- Use a Collection with custom fields: If you’re using a CMS Rich Text field, you can split content into two fields: one for prose, one for code, and then style the code using a plain text field wrapped in a styled
<div>
styled to appear like a code editor.
3. Use of Custom Classes
- You can assign a custom class to paragraphs or divs around code snippets and apply a monospaced font (like
Courier
or Menlo
). - While this doesn’t technically create a
<pre>
block, it simulates the appearance of code.
4. Limitations Inside CMS Rich Text
- Even with the CMS Rich Text field, Webflow doesn't allow embedded
<script>
, <iframe>
, or real <code>
elements within the text editor. - You can use custom embeds inside a Rich Text field by using the Rich Text custom elements in CMS binding combined with custom CSS/JS. This requires some setup with the Webflow CMS API or third-party tools.
Summary
You cannot natively add code blocks or preformatted <pre>
text inside a Rich Text element in Webflow. To include JSON or other code samples, use Embed elements styled manually, or create a styled div with monospaced font outside the Rich Text. For CMS, consider using custom fields for code snippets and styling them to resemble code blocks.