To remove a section from an Astro theme, open the page that renders it (usually src/pages/index.astro), delete the section’s component tag and its import line, then remove any navigation link or data file that only that section used. Run npx astro check and npm run build afterwards; both will point at anything that still references the removed piece.
Key Takeaways
- A homepage section is almost always one component tag plus one import in a page file.
- Delete the tag and the import together, or the build keeps bundling an unused file.
- Leave the component file in
src/components/until the site is live, then delete it.- Remove matching nav links, anchor IDs and data entries, or you ship dead links.
- Removing a whole page needs a redirect if the URL was ever public.
Find where the section is rendered
Theme homepages are usually a stack of section components inside a layout. Open the page and you will see something like this:
---
// src/pages/index.astro
import BaseLayout from '../layouts/BaseLayout.astro';
import Hero from '../components/sections/Hero.astro';
import LogoCloud from '../components/sections/LogoCloud.astro';
import Features from '../components/sections/Features.astro';
import Testimonials from '../components/sections/Testimonials.astro';
import Pricing from '../components/sections/Pricing.astro';
import CallToAction from '../components/sections/CallToAction.astro';
---
<BaseLayout title="Home">
<Hero />
<LogoCloud />
<Features />
<Testimonials />
<Pricing />
<CallToAction />
</BaseLayout>
If you are not sure which component draws the block you see in the browser, search for a phrase from it: grep -rn "Trusted by" src/. The match tells you the component file, and searching for that file name tells you which page imports it.
Delete the tag and the import
To drop the testimonials and logo strip, remove both the tags and their imports:
---
// src/pages/index.astro
import BaseLayout from '../layouts/BaseLayout.astro';
import Hero from '../components/sections/Hero.astro';
import Features from '../components/sections/Features.astro';
import Pricing from '../components/sections/Pricing.astro';
import CallToAction from '../components/sections/CallToAction.astro';
---
<BaseLayout title="Home">
<Hero />
<Features />
<Pricing />
<CallToAction />
</BaseLayout>
An import you no longer use still makes Astro process that component, and in some setups its styles and scripts still end up in the bundle. Deleting the import is what actually removes the code.
Keep the component file itself for now. If you change your mind, putting a section back is a one-line change, and theme updates merge more cleanly when files the original theme ships are still where it expects them. If you are still choosing, the Astro themes catalog lets you preview every section before you buy. Our component patterns for themes article explains why themes split sections this way.
Hide a section instead of deleting it
If a section is likely to come back (a seasonal offer, a pricing table you will publish later), wrap it in a flag rather than deleting it:
---
// src/pages/index.astro
import Pricing from '../components/sections/Pricing.astro';
const showPricing = false;
---
{showPricing && <Pricing />}
Astro renders nothing for a false expression, so the section and its HTML are absent from the built page. Some themes already expose flags like this in a settings file under src/data/ or src/config.ts; check there before adding your own. The conditional rendering tip covers the other patterns.
Clean up what pointed at it
A removed section often leaves three kinds of leftovers:
- Anchor links. One-page themes link to sections by ID, for example
href="/#pricing". Search for the ID (grep -rn "#pricing" src/) and remove or retarget each link, including the footer. - Navigation entries. If the section had a menu item, remove it from the navigation array. See editing the navigation menu for where themes keep it.
- Data and content. Testimonials, team members or FAQ items often live in
src/data/*.tsor a content collection. Leave the data while the component exists; delete both together when you clean up for good.
Removing a whole page
To remove a page rather than a section, delete the file in src/pages/ (or the collection entry that generates it), remove it from the navigation, and add a redirect if the URL was ever indexed:
// astro.config.mjs
import { defineConfig } from 'astro/config';
export default defineConfig({
redirects: {
'/testimonials/': '/',
},
});
The Astro redirects tip explains status codes and host-level redirects.
Check the result
# Terminal
npx astro check
npm run build
astro check reports type errors and missing imports in .astro files. The build fails on imports that point at deleted files. Then click through the site in npm run preview, including the mobile menu, because spacing between sections sometimes depended on the one you removed. The folder structure docs show where each part of a theme lives.
FAQ
Can I remove a section from an Astro theme without coding?
Mostly, yes. It is a deletion of two lines in a page file, and the build tells you if you missed something. You do need a code editor and the ability to run npm run build locally.
Will removing a section make my Astro site faster?
A little. The page ships less HTML and CSS, and fewer images if the section had them. If the section used a client:* island, removing it also removes that JavaScript.
Should I delete the component file too?
Not straight away. Keeping it makes the change easy to undo and keeps theme updates simpler to merge. Delete it once you are sure, together with any data the component used.
How do I remove a section from every page at once?
If the section appears on every page, it is probably in the layout (for example a newsletter block in src/layouts/BaseLayout.astro) rather than in each page. Remove it from the layout file once.