How to create block pinning effects on Squarespace
Create block pinning effects on Squarespace by adding custom CSS code that uses position: sticky or position: fixed properties to specific block elements. This requires identifying block IDs and implementing scroll-based positioning through Code Injection.
Prerequisites
- Active Squarespace subscription with Business plan or higher
- Basic understanding of CSS custom code
- Access to Code Injection or Developer Mode
- Familiarity with Squarespace block editor
Step-by-Step Instructions
Enable Developer Tools and Identify Target Block
block-yui_ followed by a string of numbers and letters. Copy this ID as you'll need it for the CSS code.Example:
block-yui_3_17_2_1_1234567890123_12345Access Code Injection Settings
Create Basic Pinning CSS Code
<style>
#block-yui_YOUR_BLOCK_ID {
position: -webkit-sticky;
position: sticky;
top: 0;
z-index: 1000;
background: white;
}
</style>Replace
YOUR_BLOCK_ID with the actual block ID you copied in step 1.Configure Pinning Position and Offset
top value to control where the block sticks. For example:top: 0;- Pins to very top of viewporttop: 80px;- Pins 80px from top (useful if you have a sticky header)top: 10vh;- Pins 10% from top of viewport height
z-index value if the pinned block appears behind other elements.Add Responsive Behavior
<style>
#block-yui_YOUR_BLOCK_ID {
position: -webkit-sticky;
position: sticky;
top: 0;
z-index: 1000;
}
@media screen and (max-width: 768px) {
#block-yui_YOUR_BLOCK_ID {
position: relative;
top: auto;
}
}
</style>Implement Advanced Scroll-Based Effects
<script>
window.addEventListener('scroll', function() {
var block = document.getElementById('block-yui_YOUR_BLOCK_ID');
var scrolled = window.pageYOffset;
if (scrolled > 200) {
block.style.position = 'fixed';
block.style.top = '0';
} else {
block.style.position = 'relative';
}
});
</script>Test and Refine the Pinning Effect
- The block pins at the correct scroll position
- Other content flows properly around the pinned block
- The effect works on different devices and browsers
- No layout shifts or jumping occurs during scrolling
Optimize Performance and Accessibility
<style>
#block-yui_YOUR_BLOCK_ID {
position: -webkit-sticky;
position: sticky;
top: 0;
z-index: 1000;
transition: all 0.3s ease;
}
@media (prefers-reduced-motion: reduce) {
#block-yui_YOUR_BLOCK_ID {
transition: none;
}
}
</style>Common Issues & Troubleshooting
Block ID changes after editing the page
Squarespace sometimes regenerates block IDs when content is modified. Re-inspect the element to get the new ID and update your CSS code accordingly. Consider using more stable selectors like .sqs-block-[block-type] when possible.
Pinned block appears behind other elements
Increase the z-index value in your CSS. Squarespace headers typically use z-index values around 1000-2000, so try values like z-index: 2001; to ensure your pinned block appears on top.
Layout shifts or content jumping during scroll
Add a placeholder element or set specific dimensions to prevent layout shifts:
.pinned-block-container::before {
content: '';
display: block;
height: [block-height]px;
visibility: hidden;
} Pinning doesn't work on mobile devices
Some mobile browsers have limited support for position: sticky. Use JavaScript fallbacks with position: fixed and scroll event listeners, or disable pinning on mobile using media queries: @media (max-width: 768px) { position: relative !important; }