This exercise is designed to walk you through the process of creating a simple website from scratch. It will involve the key steps in web development, such as HTML structure, CSS styling, and basic interactivity with JavaScript. By the end of the exercise, you'll have a basic but functional website that you can expand and modify according to your needs.
Build a simple, responsive website with the following sections:
Before you start coding, you need to create the necessary folders and files for your website project.
/my-website
/assets
/css
style.css
/images
(store your images here)
/js
script.js
index.html
index.html: The main HTML file.style.css: The stylesheet for the website.script.js: JavaScript file to add interactivity.Now, you will create the basic structure of the webpage. Here's how to set up your index.html file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Simple Website</title>
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<!-- Header Section -->
<header>
<h1>Welcome to My Website</h1>
<p>This is a simple website built with HTML, CSS, and JavaScript.</p>
</header>
<!-- Navigation Bar -->
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#services">Services</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
<!-- Main Content Section -->
<main>
<section id="home">
<h2>Home</h2>
<p>This is the homepage section.</p>
</section>
<section id="about">
<h2>About</h2>
<p>This is the about section. Here you can tell more about your website.</p>
</section>
<section id="services">
<h2>Services</h2>
<p>This is the services section. You can list the services you offer here.</p>
</section>
<section id="contact">
<h2>Contact</h2>
<p>This is the contact section. Include your contact information here.</p>
</section>
</main>
<!-- Footer Section -->
<footer>
<p>© 2024 My Website. All rights reserved.</p>
</footer>
<script src="assets/js/script.js"></script>
</body>
</html>
id (e.g., id="home") so users can navigate directly to them via the links in the navigation bar.Now, you will create the CSS styles to make the website visually appealing. Here’s an example of style.css:
/* Global Styles */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
box-sizing: border-box;
}
h1, h2 {
color: #333;
}
a {
text-decoration: none;
color: #fff;
}
/* Header Styling */
header {
background-color: #4CAF50;
padding: 20px;
color: white;
text-align: center;
}
/* Navigation Bar Styling */
nav {
background-color: #333;
}
nav ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
nav ul li {
display: inline;
padding: 14px 16px;
}
nav ul li a:hover {
background-color: #111;
}
/* Main Content Styling */
main {
padding: 20px;
}
section {
margin-bottom: 40px;
}
section h2 {
color: #4CAF50;
}
/* Footer Styling */
footer {
background-color: #333;
color: white;
text-align: center;
padding: 10px;
}
footer p {
margin: 0;
}
Now, add basic interactivity with JavaScript. In this example, you’ll create a simple function that displays an alert when a user clicks on the "Contact" section link.
// script.js
document.querySelector('a[href="#contact"]').addEventListener('click', function() {
alert("Thank you for visiting the contact section!");
});
Open the Website Locally:
index.html file in a web browser to see how the website looks and functions.Check Responsiveness:
Test Interactivity:
Enhance Design:
Add More Features:
Optimize for SEO:
<head> section of index.html to improve the SEO of the site (e.g., meta description, keywords, etc.).This exercise demonstrates the essential steps in creating a simple website: setting up HTML structure, styling with CSS, and adding interactivity with JavaScript. You can expand this project by adding more content, enhancing the design, or incorporating more advanced features such as forms, animations, and JavaScript frameworks.
As you progress, you’ll learn more about website optimization, accessibility, and other important considerations in web development.
Open this section to load past papers