How to Build a Personal Website Using HTML, CSS, and JavaScript
Building a personal website is an excellent way to showcase your skills, portfolio, and personal brand. This tutorial will guide you through the steps to create a simple yet professional personal website using HTML, CSS, and JavaScript.
Step 1: Setting Up Your Project
- Create a new directory for your project and navigate into it.
- Inside the directory, create three files:
index.html
,styles.css
, andscript.js
.
Step 2: Writing the HTML
Open index.html
and add the following code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Personal Website</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>Welcome to My Website</h1>
</header>
<main>
<section>
<h2>About Me</h2>
<p>A brief introduction about yourself.</p>
</section>
<section>
<h2>Portfolio</h2>
<p>Showcase your work here.</p>
</section>
</main>
<script src="script.js"></script>
</body>
</html>
Step 3: Adding Some Style with CSS
Open styles.css
and add the following CSS to style your website:
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
header {
background-color: #333;
color: white;
padding: 1rem;
text-align: center;
}
main {
padding: 1rem;
}
section {
margin-bottom: 2rem;
}
Step 4: Adding Interactivity with JavaScript
Open script.js
and add the following JavaScript code to add some interactivity:
document.addEventListener('DOMContentLoaded', () => {
const header = document.querySelector('header');
header.addEventListener('click', () => {
header.style.backgroundColor = header.style.backgroundColor === 'blue' ? '#333' : 'blue';
});
});
Conclusion
Congratulations! You have built a basic personal website using HTML, CSS, and JavaScript. You can now expand upon this foundation to create a more complex and personalized website.
For more tutorials and tips, visit pito.dev.