Apply your knowledge to build something amazing!
:information_source: Info Project Details Difficulty Level: Beginner
Estimated Time: 2-3 hours
Skills Practiced:
graph LR
A[Setup Environment] --> B[Create Header Component]
B --> C[Build Section Component]
C --> D[Add Info Section]
D --> E[Add Hobby Section]
E --> F[Add Personality Section]
F --> G[Create Footer Component]
G --> H[Style with CSS/Bootstrap]
H --> I[Test & Submit]
style A fill:#e1f5e1
style B fill:#d4e9f7
style C fill:#d4e9f7
style D fill:#ffd4a3
style E fill:#ffd4a3
style F fill:#ffd4a3
style G fill:#d4e9f7
style H fill:#f5d4e1
style I fill:#e1e1f5
Click on the + symbol button to add a new file
Rename the file by clicking the name of the file tab.
Mini Project: Svelte REPL [ Remove all the codes before doing project. ]
:warning: Important Setup Step Before starting, make sure to:
- Open the Svelte REPL link
- Delete ALL existing code in the editor
- Start with a clean slate to avoid confusion
Let's create a biography page of yourself!
Your biography page will include your basic info, hobby, personality and social media links.
In this project, you will be using the skills and knowledge of Svelte you've learnt previously, such as Svelte Props and Svelte Components.
This is an example of a basic biography:
The above example is without any CSS styles added. You can add your own CSS or Bootstrap classes.
tip Best Practice Work on one component at a time and test it before moving to the next. This makes debugging much easier!
Let's create a Header.svelte
component for our website.
Inside the Header.svelte file:
title
without any value.<h1>
tag and set the title variable inside it by using curly braces.<!-- Header.svelte -->
<script>
// Export the title prop so it can be set from parent component
export let title;
</script>
<h1>{title}</h1>
Inside the App.svelte file:
'./Header.svelte'
<Header>
tag.title
of the <Header>
tag with "My Biography" as the value.<!-- App.svelte -->
<script>
import Header from './Header.svelte';
</script>
<Header title="My Biography" />
:information_source: Info Milestone Checkpoint 1 :white_check_mark: You should now see "My Biography" as a heading on your page
:white_check_mark: The Header component is successfully receiving props
:white_check_mark: If you don't see the heading, check your import path and prop name
Now let's have an Info, Hobby and Personality section but using only one component.
tip Component Reusability We're creating ONE Section component that we'll reuse THREE times. This is a key concept in component-based development!
Create a component called Section.svelte
Inside the Section.svelte file:
Declare four variables without values and export it:
title
item1
item2
item3
Copy-paste the HTML code below:
<div>
<h3>\{title\}</h3>
<p>\{item1\}</p>
<p>\{item2\}</p>
<p>\{item3\}</p>
</div>
Inside the App.svelte file:
'./Section.svelte'
<Section>
tag.myInfo
with these properties:
title
with value "Info".item1
as your name.item2
as your age.item3
as your school.// Replace with your own information!
let myInfo = {
title: "Info",
item1: "Lee Kah Fai", // Your name
item2: 14, // Your age
item3: "SMJK (C) Chung Ling", // Your school
}
<Section>
tag, set the myInfo object as the prop:<Section {...myInfo} />
:warning: Common Mistake Make sure you use the spread operator
{...myInfo}
correctly. This passes all properties of myInfo as individual props to the Section component.
:information_source: Info Milestone Checkpoint 2 :white_check_mark: You should now see your Info section with your personal details
:white_check_mark: The Section component is receiving all four props correctly
:white_check_mark: If any data is missing, check that all prop names match exactly
Now do the same for a Hobby and Personality section by reusing the Section.svelte
component. You don't need to create another component, you can just re-use the Section.svelte
component to make each section.
You can do this by creating 2 more object variables for Hobby and Personality.
Then change each of the properties to their respective values.
// Example structure for hobby section
let myHobby = {
title: "Hobbies",
item1: "Playing piano",
item2: "Cooking",
item3: "Play badminton"
}
// Example structure for personality section
let myPersonality = {
title: "Personality",
item1: "Quiet",
item2: "Humble",
item3: "Kind"
}
Examples of hobbies can be:
Examples of personality can be:
tip Make It Personal Choose hobbies and personality traits that truly represent you! This is YOUR biography page.
:information_source: Info Milestone Checkpoint 3 :white_check_mark: You should now have THREE sections: Info, Hobbies, and Personality
:white_check_mark: Each section uses the same Section component
:white_check_mark: All sections display different content based on the props passed
For the Footer part, you need to create another component called Footer.svelte
file.
Inside the Footer.svelte file:
name
without any value.<p>
tag and set the name variable inside it by using curly braces, with the text (c) All rights reserved.
after it.<!-- Footer.svelte -->
<script>
export let name;
</script>
<p>{name} (c) All rights reserved.</p>
Inside the App.svelte file:
'./Footer.svelte'
<Footer>
tag.name
of the <Footer>
tag with your name from the {myInfo.item1}
as the value.<Footer name={myInfo.item1} />
:information_source: Info Milestone Checkpoint 4 :white_check_mark: Footer displays at the bottom with your name and copyright text
:white_check_mark: The name is dynamically pulled from your myInfo object
:white_check_mark: Basic biography structure is complete!
Make the project look nice by adding Bootstrap classes or CSS style tags.
:warning: Bootstrap Setup Make sure to add the Bootstrap link BEFORE you start using Bootstrap classes, otherwise the styling won't work!
You can add Bootstrap 5 by adding this tag anywhere in your App.svelte
file:
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
Try to play around with the CSS code and make your own design. Make it look unique and special.
Feel free to add <div>
tags or more sections and information as you like.
If you want to add images, you can just find the link to the image. Then you can just write the file name src="[image-url]"
for the source attribute.
You can go to Color Hunt to find colours for your biography too. Or you can just use Bootstrap colours such as "bg-primary" or "text-white".
Be creative in your own way.
Component not showing up:
Props not displaying:
Spread operator error:
{...objectName}
not {objectName}
Bootstrap styles not working:
tip Quick Debug Check Open your browser's console (F12) to see if there are any error messages. Svelte provides helpful error messages!
Ready to take your biography to the next level? Try these challenges:
Create a new component for social media links with icons:
<!-- SocialLinks.svelte -->
<script>
export let links = [];
</script>
<div class="social-links">
{#each links as link}
<a href={link.url} target="_blank">{link.name}</a>
{/each}
</div>
Make sections expandable/collapsible:
<script>
let isExpanded = false;
</script>
<button on:click={() => isExpanded = !isExpanded}>
{isExpanded ? 'Hide' : 'Show'} {title}
</button>
Add a light/dark mode toggle:
<script>
let isDarkMode = false;
</script>
<button on:click={() => isDarkMode = !isDarkMode}>
{isDarkMode ? '🌞' : '🌙'}
</button>
Add fade-in animations to your sections using Svelte transitions.
Create language toggle to show your biography in different languages.
My Biography (Code Review) https://youtu.be/cNM3CWwIRbU
Code with AI: Enhance your biography page.
Prompts:
Before submitting, ensure you have:
When you have completed your project, submit it using the link below:
Make sure to test your webpage before submitting to ensure all required elements are working properly!
tip Final Encouragement Congratulations on building your first Svelte biography page! You've learned component creation, props, and reusability - fundamental concepts in modern web development. Keep experimenting and adding your own creative touches! :tada: