Squarespace Code Block

You want to add custom HTML, CSS, or JavaScript to your Squarespace page - and the Code Block is the tool that makes it possible without touching site-wide settings or breaking anything else. Squarespace Code Blocks accept raw HTML, CSS, and JavaScript and render them inline at any position on any page. They are available on Business plans and above ($23/month) and are the primary way to embed third-party widgets, build custom layouts, and add interactive elements the visual editor cannot produce.

The Squarespace Code Block is the bridge between the visual editor and custom web development. It lets you embed any third-party widget, build custom HTML elements, run page-specific JavaScript, and create any component the standard block library does not include. This guide covers how to add a Code Block, what you can build with one, how it differs from Code Injection, and best practices for keeping your code clean and functional.

Squarespace Code Block

Code Blocks are different from Code Injection. Code Injection runs in the header or footer of every page - it is for site-wide scripts. Code Blocks insert code at a specific position on a specific page - they are for page-specific content and visual elements. Understanding this distinction is the foundation of using both tools effectively. Squarespace includes Code Blocks on Business plans and above. Use coupon code OKDIGITAL10 for 10% off any Squarespace plan.

 Squarespace Code Block - a web designer

How to Add a Code Block in Squarespace

Step 1: Open the Page Editor

Navigate to the page where you want to add custom code. Click Edit to open the page editor. Click a content insertion point (the plus icon between blocks or sections).

Step 2: Select Code from the Block Menu

In the block menu, find and click Code. If it does not appear in the initial list, click More to see the full block library. The Code Block opens a text editor panel.

Step 3: Paste or Write Your Code

Enter your HTML, CSS, or JavaScript in the editor. Check that the display mode at the bottom is set to HTML (not Markdown). Click Apply to save. The code renders immediately in the page preview at the position where you placed the block.

Step 4: Preview and Test

Check the rendered output in the page preview. Open the published page in a new browser tab to verify it works on the live site. Test on mobile to ensure the embedded content is responsive. If something looks wrong, click the Code Block to reopen the editor and adjust your code.

What You Can Build with Squarespace Code Blocks

Embedded Third-Party Widgets

The most common Code Block use case is embedding third-party tools - Google Maps, Calendly booking widgets, Typeform surveys, Shopify Buy Buttons, social media feeds, and any service that provides an HTML embed code. Paste the embed code into a Code Block and it renders on your page. For embedding techniques, our guide to HTML code embedding on Squarespace covers every common widget type.

Custom HTML Elements

Build page elements that the visual editor cannot create - pricing tables, comparison charts, team member cards, FAQ accordions, custom call-to-action banners, and styled data tables. Write the HTML structure in the Code Block and style it with Custom CSS. For HTML building techniques, our guide to Squarespace custom HTML covers common elements and responsive design.

Interactive JavaScript Components

Code Blocks support JavaScript alongside HTML. Build interactive calculators, dynamic content filters, countdown timers, tabbed content sections, and animated elements. The JavaScript runs in the context of the page, so it has access to the DOM and can modify surrounding Squarespace elements if needed.

Custom Styled Text Sections

For text layouts that the standard Text Block cannot produce - multi-column text, pull quotes with custom styling, highlighted text boxes, or text with background colors - a Code Block with HTML and inline CSS gives you full control over the presentation.

Code Block vs. Code Injection vs. Custom CSS

Code Block: Inserts code at a specific position on a specific page. Best for embedded widgets, custom HTML elements, and page-specific interactive components. Renders inline with surrounding content blocks.

Code Injection: Inserts code into the header or footer of every page (or a specific page's header). Best for analytics scripts, tracking pixels, custom font imports, and site-wide JavaScript. Does not render visible content at a specific page position.

Custom CSS: Accepts CSS rules only - no HTML or JavaScript. Applies to every page. Best for visual styling changes to existing elements. Available on all plans. For a detailed comparison, our guide to custom code injection on Squarespace covers every injection point.

Code Block Best Practices

Set the mode to HTML. The Code Block editor has a display mode toggle at the bottom - HTML and Markdown. For most use cases, you want HTML mode. Markdown mode does not support JavaScript and processes the content differently.

Keep code clean and commented. Add HTML comments explaining what each section of code does. If you return to edit the Code Block months later, the comments save you from guessing what each div is for.

Style with Custom CSS, not inline styles. While inline styles work in Code Blocks, they are harder to maintain and cannot be overridden by media queries for responsive design. Add class names to your HTML elements and write the CSS rules in Design > Custom CSS. For CSS techniques, our guide to adding custom CSS to Squarespace covers best practices.

Make everything responsive. Use percentage widths instead of fixed pixels. Add CSS media queries for mobile breakpoints. Test on actual mobile devices. A Code Block that looks great on desktop but breaks on mobile is worse than having no custom element at all.

Validate your HTML. Malformed HTML - unclosed tags, missing quotes, broken nesting - can affect the rendering of surrounding Squarespace blocks. Paste your code into an HTML validator before adding it to the Code Block.

Minimize JavaScript in Code Blocks. For small, page-specific scripts, Code Blocks work fine. For larger scripts or libraries, load them through Code Injection and reference them from the Code Block. This keeps the Code Block clean and ensures scripts load in the correct order.

Common Code Block Mistakes

Using Markdown mode for HTML. If your embed code or HTML is not rendering, check the display mode toggle. Markdown mode strips or alters HTML tags. Switch to HTML mode.

Forgetting that Code Blocks are page-specific. A Code Block only exists on the page where you added it. If you need the same element on multiple pages, you need to add separate Code Blocks to each page - or use Code Injection for site-wide elements.

Not testing on mobile. Fixed-width elements in Code Blocks are the most common cause of horizontal scroll bars on mobile Squarespace pages. Always set widths to 100% or use max-width containers.

Loading heavy scripts inline. A Code Block that loads a large JavaScript library adds that download to the specific page's load time. If the library is used on multiple pages, load it once through Code Injection and reference it from each Code Block. For performance considerations, our Squarespace performance tweaks guide covers script optimization.

Squarespace Code Block Examples

These are the most practical Code Block patterns you can drop into any Squarespace page.

Responsive Embed (for any iframe widget)

<div style="position:relative; padding-bottom:56.25%; height:0; overflow:hidden;">   <iframe src="YOUR_EMBED_URL" style="position:absolute; top:0; left:0; width:100%; height:100%;" frameborder="0" allowfullscreen></iframe> </div>

This wrapper makes any fixed-size iframe - Calendly, YouTube, Vimeo, Google Maps - fully responsive on mobile. Replace YOUR_EMBED_URL with the embed source from whichever service you are integrating.

Custom Styled Button

<a href="/your-page" style="display:inline-block; background:#000; color:#fff; padding:14px 28px; text-decoration:none; font-family:sans-serif; font-size:15px; border-radius:4px;">Book a Call</a>

Use this when you need a button with a specific style that does not match your theme's default button styles. Adjust the background colour, padding, and font to match your brand.

Simple Announcement Banner

<div style="background:#f5f0e8; border-left:4px solid #c8a96e; padding:16px 20px; font-family:sans-serif; font-size:14px;">   <strong>Limited time:</strong> Book before June 30 and save 20%. </div>

Add this above a pricing section or service description to draw attention to a promotion without affecting your template's built-in announcement bar.

Troubleshooting Code Block Issues

Code Not Rendering

Check the display mode (HTML vs. Markdown). Verify the code is complete - missing closing tags or incomplete script references prevent rendering. Check the browser console for JavaScript errors.

Code Block Breaks Page Layout

An element with a fixed width larger than the page container causes overflow. Set width to 100% or wrap elements in a container with overflow: hidden. Unclosed HTML tags can also affect surrounding blocks - validate your HTML.

Code Works in Preview but Not on Published Site

Browser caching can show the old version of the published page. Clear cache or check in incognito. Some scripts behave differently in the editor preview vs. the live site because the editor loads additional Squarespace scripts that may conflict. For design consistency, our Squarespace design tips guide covers preview and testing workflows.

Frequently Asked Questions

What is a Squarespace Code Block?

A Code Block is a content block that accepts raw HTML, CSS, and JavaScript. It renders custom code inline with your page content at the exact position where you place it. Code Blocks are available on Business plans and above ($23/month billed annually).

How do I add a Code Block in Squarespace?

Open the page editor, click the plus icon at a content insertion point, and select Code from the block menu (under More if it is not immediately visible). Paste your HTML, CSS, or JavaScript into the editor, confirm the display mode is set to HTML (not Markdown), and click Apply. The code renders immediately in the page preview.

What is the difference between a Code Block and Code Injection in Squarespace?

Code Blocks insert code at a specific position on a specific page - use them for embedded widgets, custom HTML elements, and page-specific interactive components. Code Injection inserts code into the header or footer of every page - use it for analytics scripts, tracking pixels, and site-wide JavaScript. Use Code Blocks for visible, positioned content; use Code Injection for background scripts.

Do I need a Business plan for Code Blocks in Squarespace?

Yes. Code Blocks are available on Business plans and above. Personal plan users cannot add Code Blocks to their pages. Custom CSS (which accepts CSS only, no HTML or JavaScript) is available on all plans. If you only need style tweaks, the Personal plan is sufficient - but for custom embeds and HTML elements, Business is required.

Can I add JavaScript in a Squarespace Code Block?

Yes. Code Blocks support JavaScript alongside HTML and CSS. For page-specific scripts, Code Blocks are the right location. For site-wide scripts or libraries, load them once through Code Injection in the header and reference them from the Code Block - this keeps load order correct and avoids loading the same library multiple times.

Why is my Squarespace Code Block not rendering?

The most common cause is the display mode being set to Markdown instead of HTML. Check the toggle at the bottom of the Code Block editor and switch it to HTML. Other causes include incomplete code (missing closing tags), JavaScript errors (check the browser console), or a third-party embed script that requires HTTPS and is blocked by the browser.

Can I use Code Blocks on multiple pages?

Yes, but each Code Block is independent and page-specific. You need to add a separate Code Block to each page where you want the custom code to appear. For code that should run on every page - tracking pixels, chat widgets, font imports - use Code Injection in the site header instead of individual Code Blocks.

What can I embed with a Squarespace Code Block?

Any service that provides an HTML embed code can be added via a Code Block - Google Maps, Calendly, Typeform, Shopify Buy Button, social media feeds, YouTube playlists, custom chat widgets, and interactive calculators. Paste the embed code into the Code Block, confirm the display mode is HTML, and the widget renders on your page.

Use Code Blocks to Build What the Editor Cannot

The Squarespace Code Block is the most powerful content block available. It bridges the gap between the visual editor's limitations and the full capabilities of HTML, CSS, and JavaScript. Embedded widgets, custom elements, interactive components, and styled sections - all of it lives in Code Blocks.

Keep your code clean, style with Custom CSS rather than inline styles, make everything responsive, and test on mobile. A well-implemented Code Block enhances your page seamlessly. A poorly implemented one breaks it visibly.

Keep Reading

* Read the rest of the post and open up an offer
Top