BLOG
Squarespace Custom Code: What You Can Safely Paste (and What Breaks)
A code block looks like a blank canvas. It is not. It sits inside someone else's page structure, inherits someone else's CSS, and punishes full-document markup in ways that only show up after you hit save.
The pain: paste, save, and half the page changes
Someone sends you a block of HTML - a pricing table, a signup form, an embed from a marketing tool. You add a code block in Squarespace, paste it in, hit save, and one of two things happens. Either the block looks fine but the sections around it have quietly changed: wider text, different spacing, a font that no longer matches. Or the block itself renders as a wall of raw text, because something in it got escaped along the way.
Both outcomes have the same root cause: the code block is a window into the middle of an existing page, not a standalone page. What you paste is being inserted into a structure Squarespace built, and the theme's CSS keeps applying to everything inside your block. Understanding what survives that environment - and what does not - removes most of the risk.
What is safe to paste
Think of a code block as accepting a fragment: content that could sit anywhere inside a page without claiming to be a page itself. In practice:
- Content elements. Headings, paragraphs, lists, images, links, tables, buttons. The everyday building blocks. These are what code blocks are for.
-
Embedded widgets. Most third-party services hand you a snippet - a
<iframe>or adivplus a<script>tag. These are designed to be dropped into foreign pages and generally behave. -
Scoped styles. A
<style>block is allowed, and it works - but its rules apply to the whole page, not just your snippet. Writing selectors that only match inside your own container class is what keeps it safe. More on this below. -
Small scripts. Plain JavaScript inside a
<script>tag runs. Scripts that create their own elements and manipulate only those elements are fine.
What breaks things
A full HTML document
If your snippet starts with <!DOCTYPE html> or contains
<html>, <head> or <body> tags, it is a
whole page, not a fragment. Browsers are forgiving and will try to render it anyway, but the
result is unpredictable: tags get reordered, meta content leaks into the visible page, and the
theme's layout can shift. If someone sends you a full document, extract only the section you
need - the block between the body tags that contains your actual content.
Global selectors
A style rule like h2 { color: navy; } inside your snippet's style block does not
recolor the headings in your block. It recolors every heading on the page. This is the
single most common cause of "I added one section and the whole site changed." Scope every rule to
a container class that only your snippet uses:
/* unscoped: hits the whole page */
h2 { color: navy; }
/* scoped: only inside your block */
.my-pricing h2 { color: navy; }
Class names that collide with the theme
Generic class names like container, row, col-6 or
button may already exist in the theme's CSS with completely different rules attached.
Your block inherits them, and the layout goes sideways. Prefix your class names with something
unique to the project - acme-pricing-row instead of row - and collisions
become impossible.
Markup pasted from a rich-text editor
Copying code from Word, Google Docs, an email client or a chat window can substitute straight quotes with curly ones, strip angle brackets, or insert invisible characters. The code block then renders your HTML as literal text. Always copy code from a plain-text surface, and if a snippet came through one of those channels, run it through a formatter first to see what actually arrived.
Limitation: code injection points and available blocks vary by Squarespace plan and version. This article is about making the content of a code block safe, not about which injection points your plan exposes. CardKit is not affiliated with Squarespace.
A test loop that catches damage before visitors do
The reason paste-and-save feels dangerous is that the failure is only visible after saving - and on a live page. A simple loop makes it safe:
- Render the snippet outside the site first. Paste it into a sandbox that shows the rendered result - the CSS Code Editor renders a pasted section live and lets you click elements to edit them, which is also how you adapt the snippet's text and images before it ever reaches Squarespace.
- Check the scope of every style rule. Each selector in the snippet's CSS should start with your unique container class. If any rule would match elements outside the snippet, scope it or delete it.
- Paste into a draft page, not the live one. Squarespace drafts let you save and preview without publishing. Look at your surrounding sections: if their fonts or spacing moved, one of your selectors is leaking.
- Check mobile width before promoting the block to the live page. Snippets with fixed widths or multi-column grids are the ones that overflow on phones.
Real scenarios
The newsletter embed that restyled the blog. A marketing tool's embed snippet
shipped with input { border-radius: 0; } in its style block. Suddenly every input
field on the site, including search and comments, lost its rounding. Scoping the rule to the
embed's own wrapper class fixed it in one line.
The pricing table from an agency. The table arrived as a full HTML document with inline styles on every tag. Pasting the body content alone, then stripping the inline styles down to a scoped style block, made the table both safer and half the size. The cleanup method - format, inspect, remove junk without touching structure - is the subject of our article on cleaning up exported HTML.
The template buyer adapting a Squarespace site. She purchased an HTML template section to recreate inside her code block. Instead of pasting the whole page, she pasted one section at a time, checked each against the theme, and stopped when something conflicted. Working one section at a time is the same isolation principle from our guide on editing templates without breaking the layout - it applies to code blocks exactly as it applies to template files.
The mindset
Safe code-block work comes down to one principle: your snippet is a guest in someone else's page. Guests scope their styles, prefix their class names, arrive as fragments rather than documents, and get tested on a draft before they meet the public. Follow that, and the code block stops being the thing that breaks your site and becomes what it was meant to be: a controlled way to add anything the standard blocks do not offer.