📖 Scenario: You are building a simple webpage using Svelte. To help search engines understand your page, you need to add SEO-friendly meta tags in the HTML head section.
🎯 Goal: Create a Svelte component that sets the page title and meta description using the <svelte:head> tag.
📋 What You'll Learn
Use the <svelte:head> tag to add elements inside the HTML head.
Set the page title to exactly My Svelte SEO Page.
Add a meta description tag with the content This is a simple Svelte page with SEO meta tags..
Ensure the meta tags are correctly placed inside the <svelte:head> block.
💡 Why This Matters
🌍 Real World
Adding SEO meta tags is essential for making web pages discoverable and understandable by search engines and social media platforms.
💼 Career
Web developers often need to add and manage meta tags to improve website SEO and user experience.
Progress0 / 4 steps
1
Create the Svelte component skeleton
Create a new Svelte component file and write the basic structure with an empty <svelte:head> block.
Svelte
Hint
Start by adding the <svelte:head> tag to your component. This tag lets you add elements inside the HTML head.
2
Add the page title inside <svelte:head>
Inside the existing <svelte:head> block, add a <title> tag with the exact text My Svelte SEO Page.
Svelte
Hint
The <title> tag sets the page title shown in browser tabs and search results.
3
Add a meta description tag
Inside the <svelte:head> block, below the title tag, add a <meta> tag with name="description" and content="This is a simple Svelte page with SEO meta tags.".
Svelte
Hint
The meta description helps search engines understand what your page is about.
4
Add a main heading to the page content
Inside the <main> tag, add an <h1> heading with the text Welcome to My Svelte SEO Page.
Svelte
Hint
The main heading helps users and search engines understand the page content.
Practice
(1/5)
1. What is the main purpose of using <svelte:head> in a Svelte component?
easy
A. To create reactive variables
B. To style the component with CSS
C. To handle user input events
D. To add SEO meta tags like title and description to the page head
Solution
Step 1: Understand the role of <svelte:head>
The <svelte:head> tag is used to insert elements into the HTML document's <head> section.
Step 2: Identify what goes inside <svelte:head>
SEO meta tags like <title> and <meta name="description"> are placed inside <svelte:head> to improve search engine visibility.
Final Answer:
To add SEO meta tags like title and description to the page head -> Option D
Quick Check:
SEO meta tags = <svelte:head> usage [OK]
Hint: Use <svelte:head> to add meta tags in the page head [OK]
Common Mistakes:
Confusing <svelte:head> with styling or event handling
Trying to add meta tags outside <svelte:head>
Using <svelte:head> for component layout
2. Which of the following is the correct syntax to set the page title inside a Svelte component?
easy
A. My Page
B. My Page
C. My Page
D. My Page
Solution
Step 1: Recall correct Svelte syntax for head elements
In Svelte, <svelte:head> is the special tag to add elements to the document head.
Step 2: Check each option for correctness
<svelte:head><title>My Page</title></svelte:head> correctly wraps <title> inside <svelte:head>. Plain <head><title>My Page</title></head> and bare <title>My Page</title> miss the special Svelte tag. <svelte:title>My Page</svelte:title> uses a non-existent tag.
Final Answer:
<svelte:head><title>My Page</title></svelte:head> -> Option A
Quick Check:
Page title in <svelte:head> = correct syntax [OK]
Hint: Always wrap head tags inside <svelte:head> in Svelte [OK]
Common Mistakes:
Using plain <head> instead of <svelte:head>
Placing <title> outside any head tag
Using invalid tags like <svelte:title>
3. What will be the rendered HTML head content after this Svelte component runs?