How to Set Page Title in Astro: Simple Guide
In Astro, set the page title by adding a
<title> tag inside the <head> section of your component or page. This updates the browser tab title and improves SEO.Syntax
Use the <title> tag inside the <head> section in your Astro component or page. The <title> tag defines the text shown in the browser tab.
The structure looks like this:
<head>: The HTML head section where metadata goes.<title>: The page title text.
html
<head> <title>Your Page Title Here</title> </head>
Example
This example shows a complete Astro page setting the page title to "Welcome to Astro". When you open this page in a browser, the tab will display this title.
astro
--- // No frontmatter needed for this example --- <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Welcome to Astro</title> </head> <body> <h1>Hello from Astro!</h1> </body> </html>
Output
Browser tab shows: Welcome to Astro
Page displays: Hello from Astro!
Common Pitfalls
Some common mistakes when setting the page title in Astro include:
- Placing the
<title>tag outside the<head>section, which will not update the browser tab title. - Forgetting to include the
<head>section entirely. - Using multiple
<title>tags on the same page, which can cause unpredictable results.
Always ensure the <title> tag is inside <head> and only appears once.
html
<!-- Wrong way: title outside head -->
<html>
<head>
<title>Wrong Title</title>
</head>
<body>Content</body>
</html>
<!-- Right way: title inside head -->
<html>
<head>
<title>Correct Title</title>
</head>
<body>Content</body>
</html>Quick Reference
Remember these tips when setting page titles in Astro:
- Always use
<title>inside<head>. - Set a unique and descriptive title for each page.
- Use semantic HTML for better SEO and accessibility.
- Check your browser tab to confirm the title updates correctly.
Key Takeaways
Set the page title using the tag inside the section in Astro.
Ensure the tag is placed only once per page and inside .
A clear page title improves user experience and SEO.
Check the browser tab to verify the title is set correctly.
Avoid placing outside to prevent issues.