You'll build a page that is made up of several HTML files, called components.
It'll have the following features:
Command
+ Shift
+ A
on MacOS or Ctrl
+ Shift
+ A
on Windows)Ctrl
+ `
npm install
npm run dev
Now you're ready to get coding!
Look through each file in the src
folder, which is where all the code you write will live.
You'll notice that there is no index.html
, instead, there's +page.svelte
that acts as the landing page. SvelteKit makes creating multi page websites very easy, but to do so you need to get used to some unusually named files. Just remember: +page
is an individual web page.
In +page.svelte
there are some familiar things, and some new things. The first thing that might strike you is the script
section at the top. In Svelte, all the JavaScript, HTML, and CSS for a page is stored together. This makes it easier to work on individual chunks of your website.
In the script
section it imports a Header
from a different file, and lower down on the page it uses that header.
<script>
import Header from '$lib/Header.svelte'
</script>
<Header />
This is an example of a component. The Header.svelte
file has all the code for the header, and you can import it and use it on any page. Whenever you update Header.svelte
, it will update on every page - no more copy and pasting when you want to make a small change!
In Header.svelte
you can write any CSS you want inside a style section, which goes at the bottom.
<header>
<h1 class="title">Welcome</h1>
</header>
<style>
header {
background: blue;
}
</style>
Change your header to personalise your web page.
Currently, the footer HTML and CSS is all mixed in with the rest of the page. This makes it difficult if you wanted to update the footer specifically, or you wanted to re-use it on other pages.
We're going to put all of the code for the footer into its own file, called a component. Then, we can add this component to the page without seeing all of its details. This will make our page much easier to understand, update, improve, and maintain.
src
folder, which contains all the code that you writelib
folder called Footer.svelte
+page.svelte
to Footer.svelte
+page.svelte
file<script>
import Header from '$lib/Header.svelte'
import Footer from '$lib/Footer.svelte'
</script>
Footer
component into your HTML where you want the header to beSpend some time to improve the look and feel of your site by tweaking your CSS.
Congratulations, the first iteration of your web page is complete.
You've taken the code provided and customised it to create your unique web page.
Along the way, you've learned about these parts of coding.
(➕ means new things in this project)
Svelte
➕ components
for reusable blocks of code
From here, you can take your page further, if you like, by adding images from your summer, links to your social media, YouTube channel, blog, or whatever you like.
In your coding career you will often need to look up how to do things. In this section are a couple of websites to help you find information online about how to do what you want to do.
Most frequently, a good Google search will be the best option. Remember to include the keywords "HTML", "CSS", or "Svelte" and the thing you want to do, so that Google will give you the best results (skip past the ads though!).