Fixing Excess White Space Between Header and Content (Responsive)

Fixing Excess White Space Between Header and Content (Responsive)

Large empty gaps between your header and the page content are a common Shopify theme annoyance β€” especially on mobile. This guide shows easy, safe fixes you can copy & paste into your theme CSS to remove that white space and get a tight, professional layout.


πŸ”Ž Step 1 β€” Inspect & identify where the space comes from

Before changing code, find the element creating the gap:

  • Open your store in Chrome (or any browser)
  • Right-click the empty area β†’ Inspect
  • Hover the header and the first content element to see margins/padding highlighted
  • Look for suspicious CSS like margin-top, padding-top, min-height, or large empty wrappers

Typical culprits: header wrappers with bottom margin, #MainContent with top padding, empty sections, or a sticky-header offset applied twice.


πŸ›  Step 2 β€” Add a universal CSS fix (safe, non-destructive)

Open Online Store β†’ Themes β†’ Edit code β†’ assets β†’ base.css (or theme.css) and paste this near the bottom. This resets most unwanted spacing without removing theme files.

/* Remove extra white space below header and reset content offset */
.header-wrapper,
.site-header,
.header {
  margin-bottom: 0 !important;
  padding-bottom: 0 !important;
}

main,
#MainContent {
  margin-top: 0 !important;
  padding-top: 0 !important;
}

This removes forced spacing added by theme defaults or copied custom CSS.


πŸ“± Step 3 β€” Mobile-only fix (if space appears only on phones)

If the gap shows only on small screens, add the mobile-specific snippet:

/* Mobile spacing fix */
@media (max-width: 768px) {
  .header-wrapper,
  .site-header,
  .header {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
  }

  #MainContent,
  main {
    padding-top: 0 !important;
    margin-top: 0 !important;
  }
}

🧩 Step 4 β€” Fix sticky header offset problems

Sticky headers sometimes add an offset to avoid overlap, but that offset can be incorrect. Use a variable-based safe fix (non-destructive):

/* Correct sticky header offset (uses header-height variable if available) */
body.has-sticky-header #MainContent,
body.has-sticky-header main {
  padding-top: var(--header-height, 0px) !important;
}

/* If you know your header height, set it explicitly (adjust values) */
@media (min-width: 992px) {
  body.has-sticky-header #MainContent { padding-top: 80px !important; }
}
@media (max-width: 991px) {
  body.has-sticky-header #MainContent { padding-top: 60px !important; }
}

If your theme already uses a header-height CSS variable, the first block will safely apply the correct offset. Only use explicit pixel values if you're sure about your header height.


🧹 Step 5 β€” Hide empty sections that cause gaps

Sometimes the Theme Editor includes empty (placeholder) sections that render blank space. Hide them automatically:

/* Hide empty Shopify sections to avoid blank spacing */
.shopify-section:empty {
  display: none !important;
}

This removes layout boxes that have no content.


πŸ”Ž Step 6 β€” Quick checklist to find other causes

  • Are app embeds injecting extra banners or script placeholders? (Check Customize β†’ App embeds.)
  • Did you copy custom CSS from an old theme β€” it may target old class names and create gaps.
  • Is there an announcement bar or top promo that is hidden but still occupies space? (Check header code & app settings.)
  • Are images inside the hero/banner set to a fixed height causing space? (Use responsive image styles.)

πŸ§ͺ Step 7 β€” Test your changes (how to verify)

  1. Save changes to CSS and refresh your storefront (use Incognito to avoid cached CSS).
  2. Resize the browser or use Chrome DevTools β†’ Toggle device toolbar to test mobile and tablet sizes.
  3. Check pages: homepage, collection, product page β€” sometimes only one template is affected.
  4. If you still see spacing, inspect the exact element highlighted and adjust that selector specifically (you may need a theme-specific selector).

⚠️ If the problem persists β€” targeted fixes

If the universal fixes above didn't fully remove the gap, try one of these targeted options (paste into your CSS, adjust selectors to match your theme):

/* Example: remove top padding from a theme-specific wrapper */
.template-index .page-width { padding-top: 0 !important; }

/* Example: header placeholder from an app */
.app-header-placeholder { display: none !important; }

/* Example: hero with fixed height causing spacing on mobile */
.hero-banner { min-height: 0 !important; height: auto !important; }
.hero-banner img { max-height: none !important; height: auto !important; }

Change selector names (.page-width, .hero-banner, .app-header-placeholder) to the actual classes you find in your theme's inspector.


βœ… Final checklist before publishing

  • Duplicate your theme before major edits: Online Store β†’ Themes β†’ β€’β€’β€’ β†’ Duplicate
  • Apply CSS changes to the duplicated theme and preview first
  • Test desktop, tablet, and mobile views
  • Confirm there are no hidden empty sections left

πŸŽ‰ You're Done!

After applying these styles and checks your Shopify store should no longer show large white gaps between the header and content. If you'd like, I can generate a tailored snippet for your specific theme β€” tell me the theme name (e.g., Dawn, Refresh, Sense) and I’ll provide precise selectors and example values.

Back to blog

Leave a comment