
What Causes This Error?
The “bad indentation of a mapping entry” error in Astro occurs in your frontmatter section (the area between the triple dashes ---
at the top of your .mdx
files). This error has several potential causes:
1. Inconsistent Indentation
YAML (the format used in frontmatter) is extremely sensitive to indentation. Each level of nesting must use consistent spacing:
---# Incorrect indentationlayout: ../layouts/BlogPost.astrotitle: My Blog Post author: # This line has extra spaces name: John Doe---
The correct version would align the indentation properly:
---# Correct indentationlayout: ../layouts/BlogPost.astrotitle: My Blog Postauthor: # Properly aligned name: John Doe---
2. Mixing Tabs and Spaces
One of the most common causes is mixing tabs and spaces in your indentation. YAML requires consistent use of either tabs or spaces (with spaces being the recommended approach):
---layout: ../layouts/BlogPost.astrotitle: My Blog Postauthor: name: John Doe # This line uses a tab instead of spaces---
3. Special Characters in Strings
Unescaped special characters in your frontmatter strings can break the YAML parser:
---title: 'My Page's Title' # The apostrophe breaks the string---
Limited Time Launch Sale
Skip the debugging headaches! Our AstroJS starter kit includes examples of all the frontmatter syntax, saving you hours of troubleshooting time.
GET 60% OFF!How to Fix the Error
Solution 1: Fix Quotation Marks
If your error involves strings with special characters like apostrophes or quotes, you have several options:
---# Option 1: Use double quotes for strings with apostrophestitle: "My Page's Title"
# Option 2: Use YAML's multiline string formatdescription: >- This is a long description that contains an apostrophe's and spans multiple lines without causing errors.
# Option 3: Remove quotes entirely for simple stringssimpleTitle: My Page Title---
Solution 2: Standardize Indentation
Ensure all indentation in your frontmatter uses the same character type (preferably spaces) and the same number of spaces per level (typically 2 or 4):
---meta: title: My Page description: This is my page social: image: ./social.jpg alt: Social image---
Solution 3: Use a YAML Validator
For complex frontmatter, use an online YAML validator to check your syntax before running your Astro build:
- Copy your frontmatter (without the triple dashes)
- Paste it into a YAML validator like YAML Lint
- Fix any errors highlighted by the validator
Solution 4: Check for Invisible Characters
Sometimes, invisible characters like zero-width spaces can sneak into your code, especially when copying from websites or documents:
- Open your file in a code editor that can show invisible characters
- Look for any unusual spacing or characters
- Retype the problematic lines from scratch instead of copying/pasting
Common Examples and Their Fixes
Example 1: Lists in Frontmatter
Lists in YAML require consistent formatting:
---# Incorrecttags:- astro - javascript # Wrong indentation for nested item- css
# Correcttags: - astro - javascript - css
# Also correct (alternative syntax)tags: [astro, javascript, css]---
Example 2: Complex Nested Objects
When working with deeply nested objects, maintain consistent indentation at each level:
---# Correct complex nestingproject: details: client: name: Acme Corp contact: phone: 555-1234 timeline: start: 2025-01-01 end: 2025-06-30---
By understanding these common causes and solutions, you can quickly resolve the “bad indentation of a mapping entry” error in your Astro projects. Remember that YAML is strict about formatting, so consistent indentation and proper handling of special characters are essential for smooth development.
When in doubt, simplify your frontmatter structure or use a YAML validator to catch issues before they cause build errors. With these techniques, you’ll spend less time debugging and more time building amazing websites with AstroJS.
Related Articles

How To Create A Secure Staging Environment For Cloudflare Pages
Testing website changes before they go live is essential for maintaining a professional online presence. Learn how to create a secure, password-protected staging environment for your Cloudflare Pages site.

How To Redirect .pages.dev to Your Domain
Learn how to redirect .pages.dev to your domain with this step-by-step guide

Schedule Cloudflare Pages Builds
Schedule your Cloudflare Pages builds to run at specific times. No external services needed.

Submit Your AstroJS Sitemap to Google Search Console
Submitting your AstroJS sitemap to Google Search Console is essential for ensuring your website gets properly indexed and ranks well in search results.