create web page with multi page
- User
create web page with multi page
Assistant
create web page with multi page
A great request! Here's a step-by-step guide to create a basic multi-page website using HTML, CSS, and a bit of JavaScript. We'll create a simple website with 4 pages: Home, About, Contact, and Services.
Folder Structure Create a new folder for your project and create the following subfolders and files:
project-folder/
index.html (Home page)
about.html
contact.html
services.html
css/
style.css (global styles)
js/
script.js (optional, for interactive elements)
images/ (optional, for images)
Step 1: Create the HTML Structure for each page
Create the basic HTML structure for each page. You can copy-paste the following code and modify the <title>, <h1>, and content for each page:
index.html (Home page)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home | My Website</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<header>
<nav>
<ul>
<li><a href="index.html" class="active">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="services.html">Services</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</nav>
</header>
<main>
<h1>Welcome to My Website</h1>
<p>This is the home page. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</main>
<footer>
<p>© 2023 My Website</p>
</footer>
<script src="js/script.js"></script>
</body>
</html>
about.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>About | My Website</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<header>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html" class="active">About</a></li>
<li><a href="services.html">Services</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</nav>
</header>
<main>
<h1>About Us</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sit amet nulla auctor, vestibulum magna sed, convallis ex.</p>
</main>
<footer>
<p>© 2023 My Website</p>
</footer>
<script src="js/script.js"></script>
</body>
</html>
contact.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contact | My Website</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<header>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="services.html">Services</a></li>
<li><a href="contact.html" class="active">Contact</a></li>
</ul>
</nav>
</header>
<main>
<h1>Get in Touch</h1>
<p>Send us a message: <a href="mailto:hello@example.com">hello@example.com</a></p>
</main>
<footer>
<p>© 2023 My Website</p>
</footer>
<script src="js/script.js"></script>
</body>
</html>
services.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Services | My Website</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<header>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="services.html" class="active">Services</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</nav>
</header>
<main>
<h1>Our Services</h1>
<ul>
<li>Service 1</li>
<li>Service 2</li>
<li>Service 3</li>
</ul>
</main>
<footer>
<p>© 2023 My Website</p>
</footer>
<script src="js/script.js"></script>
</body>
</html>
Notice:
<header>, <nav>, and <footer> structure..active class is added to the current page's link in the navigation menu.style.css and script.js files.Step 2: Create the global CSS styles (css/style.css)
Add the following CSS code to style your website:
/* Global Styles */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: Arial, sans-serif;
line-height: 1.6;
color: #333;
background-color: #f9f9f9;
}
header {
background-color: #333;
color: #fff;
padding: 1em;
text-align: center;
}
header nav ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
justify-content: space-between;
}
header nav ul li {
margin-right: 20px;
}
header nav a {
color: #fff;
text-decoration: none;
}
header nav a:hover {
color: #ccc;
}
header nav a.active {
color: #fff;
border-bottom: 2px solid #fff;
}
main {
display: block;
padding: 2em;
max-width: 800px;
margin: 0 auto;
}
h1 {
font-weight: bold;
font-size: 2em;
margin-bottom: 0.5em;
}
footer {
background-color: #333;
color: #fff;
text-align: center;
padding: 1em;
clear: both;
}
footer p {
margin-bottom: 0;
}
This CSS code styles the:
Step 3: Add JavaScript (optional, js/script.js)
For this example, we'll add a simple JavaScript code to highlight the current page in the navigation menu:
// Get all navigation links
const navLinks = document.querySelectorAll('header nav a');
// Loop through links and add event listener
navLinks.forEach((link) => {
link.addEventListener('click', () => {
// Remove active class from all links
navLinks.forEach((otherLink) => otherLink.classList.remove('active'));
// Add active class to the clicked link
link.classList.add('active');
});
});
This script:
.active class from all links and adds it to the clicked linkThat's it!
Now, open each HTML file (e.g., index.html, about.html, etc.) in a web browser to see your multi-page website in action.
Tips and Variations
Happy coding!