Every website you've ever visited started exactly where you are now: a blank file and an idea. Instagram, YouTube, Wikipedia—they all began with someone opening a text editor and typing the first line of HTML.
Building your first website is a rite of passage for programmers. It's the moment when your code stops living only on your computer and becomes something the whole world can see. It's magic, and it's more accessible than you might think.
In this comprehensive guide, we'll take you from zero to a published personal website. You'll learn HTML, CSS, and enough JavaScript to add interactivity. More importantly, you'll understand how the web works—knowledge that applies whether you're building a simple portfolio or the next big web app.
---
When you type a URL in your browser:
1. Your browser (the client) sends a request to a server 2. The server finds the requested files 3. The server sends those files back to your browser 4. Your browser interprets the files and displays the page
The files your browser receives are primarily:
Think of building a house:
HTML (HyperText Markup Language): The structure—walls, rooms, doors CSS (Cascading Style Sheets): The design—paint colors, furniture, decorations JavaScript: The functionality—light switches, garage door openers, smart home features
Every website uses all three (though simple sites might skip JavaScript).
---
Create a file called index.html and type:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My First Website</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>Welcome to my website!</p>
</body>
</html>
Double-click the file to open it in your browser. Congratulations—you've built a website!
<!DOCTYPE html>
Tells the browser this is an HTML5 document.
<html lang="en">
The root element of the page. lang="en" indicates the content is in English.
<head>
<!-- Metadata goes here -->
</head>
Contains information about the page (title, character set, linked files) but isn't displayed.
<body>
<!-- Visible content goes here -->
</body>
Everything the user sees goes here.
Headings:
<h1>Main Title</h1>
<h2>Section Title</h2>
<h3>Subsection Title</h3>
<!-- h1 through h6, from largest to smallest -->
Paragraphs:
<p>This is a paragraph of text. It can contain multiple sentences.</p>
<p>This is another paragraph.</p>
Links:
<a href="https://www.google.com">Visit Google</a>
<a href="about.html">About Me</a> <!-- Links to another page on your site -->
Images:
<img src="photo.jpg" alt="A description of the image">
<img src="https://example.com/image.png" alt="External image">
The alt attribute is important for accessibility and when images don't load.
Lists:
<!-- Unordered (bullet) list -->
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ul>
<!-- Ordered (numbered) list -->
<ol>
<li>Step one</li>
<li>Step two</li>
<li>Step three</li>
</ol>
Divisions (containers):
<div>
<h2>Section Title</h2>
<p>This content is grouped together.</p>
</div>
Semantic elements (meaningful containers):
<header>Site header content</header>
<nav>Navigation links</nav>
<main>Main content</main>
<section>A section of content</section>
<article>An article or post</article>
<footer>Site footer content</footer>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Alex's Portfolio</title>
</head>
<body>
<header>
<h1>Alex Johnson</h1>
<nav>
<a href="#about">About</a> |
<a href="#projects">Projects</a> |
<a href="#contact">Contact</a>
</nav>
</header>
<main>
<section id="about">
<h2>About Me</h2>
<p>I'm a student learning web development. I love creating things with code!</p>
<img src="profile.jpg" alt="Photo of Alex">
</section>
<section id="projects">
<h2>My Projects</h2>
<article>
<h3>Scratch Game</h3>
<p>A platformer game I built in Scratch.</p>
<a href="https://scratch.mit.edu/projects/...">Play it!</a>
</article>
<article>
<h3>Python Quiz</h3>
<p>An interactive quiz game in Python.</p>
</article>
</section>
<section id="contact">
<h2>Contact Me</h2>
<p>Email: alex@example.com</p>
</section>
</main>
<footer>
<p>© 2026 Alex Johnson</p>
</footer>
</body>
</html>
---
Inline styles (not recommended for most uses):
<p style="color: blue; font-size: 18px;">Blue text</p>
Internal stylesheet (in the <head>):
<head>
<style>
p {
color: blue;
font-size: 18px;
}
</style>
</head>
External stylesheet (best practice):
<head>
<link rel="stylesheet" href="styles.css">
</head>
Create a file called styles.css:
p {
color: blue;
font-size: 18px;
}
Element selector:
p {
color: blue;
} /* Affects all <p> elements */
Class selector:
<p class="highlight">Special paragraph</p>.highlight {
background-color: yellow;
} /* Affects elements with class="highlight" */
ID selector:
<p id="intro">Introduction</p>#intro {
font-size: 24px;
} /* Affects the element with id="intro" */
Combining selectors:
/* Paragraph inside a div */
div p {
margin: 10px;
}
/* Element with both classes */
.card.featured {
border: 2px solid gold;
}
Colors:
.example {
color: blue; /* Named color */
color: #3498db; /* Hex code */
color: rgb(52, 152, 219); /* RGB */
background-color: #f0f0f0;
}
Typography:
.example {
font-family: 'Arial', sans-serif;
font-size: 16px;
font-weight: bold; /* normal, bold, 100-900 */
line-height: 1.6;
text-align: center; /* left, center, right, justify */
text-decoration: none; /* none, underline, line-through */
}
Spacing:
.example {
/* Margin: space outside the element */
margin: 20px; /* All sides */
margin: 20px 10px; /* Top/bottom, left/right */
margin-top: 20px;
/* Padding: space inside the element */
padding: 20px;
padding: 10px 20px 10px 20px; /* Top, right, bottom, left */
}
Borders:
.example {
border: 1px solid black;
border-radius: 10px; /* Rounded corners */
}
Layout:
.example {
width: 300px;
max-width: 100%; /* Responsive: never wider than parent */
height: 200px;
display: block; /* block, inline, inline-block, none */
}
Flexbox makes layouts easy:
.container {
display: flex;
justify-content: center; /* Horizontal alignment */
align-items: center; /* Vertical alignment */
gap: 20px; /* Space between items */
}
Common flex patterns:
/* Navigation bar */
.nav {
display: flex;
justify-content: space-between; /* Items spread out */
align-items: center;
}
/* Centered content */
.hero {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
min-height: 100vh; /* Full viewport height */
}
/* Card grid */
.projects {
display: flex;
flex-wrap: wrap; /* Items wrap to next line */
gap: 20px;
}
.project-card {
flex: 1 1 300px; /* Grow, shrink, base width */
}
/* Reset some defaults */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* Global styles */
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.6;
color: #333;
background-color: #f9f9f9;
}
/* Header */
header {
background: linear-gradient(135deg, #667eea, #764ba2);
color: white;
padding: 40px 20px;
text-align: center;
}
header h1 {
font-size: 2.5em;
margin-bottom: 10px;
}
nav a {
color: white;
text-decoration: none;
margin: 0 15px;
font-weight: 500;
}
nav a:hover {
text-decoration: underline;
}
/* Main content */
main {
max-width: 1200px;
margin: 0 auto;
padding: 40px 20px;
}
section {
margin-bottom: 60px;
}
h2 {
color: #667eea;
border-bottom: 2px solid #667eea;
padding-bottom: 10px;
margin-bottom: 20px;
}
/* Projects grid */
.projects-grid {
display: flex;
flex-wrap: wrap;
gap: 30px;
}
.project-card {
flex: 1 1 300px;
background: white;
border-radius: 10px;
padding: 20px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
transition: transform 0.3s;
}
.project-card:hover {
transform: translateY(-5px);
}
/* Footer */
footer {
background: #333;
color: white;
text-align: center;
padding: 20px;
}
/* Responsive design */
@media (max-width: 768px) {
header h1 {
font-size: 1.8em;
}
nav a {
display: block;
margin: 10px 0;
}
.projects-grid {
flex-direction: column;
}
}
---
Inline (not recommended):
<button onclick="alert('Hello!')">Click Me</button>
Internal script (at the bottom of body):
<body>
<!-- Your HTML content -->
<script>
console.log('Page loaded!');
</script>
</body>
External script (best practice):
<body>
<!-- Your HTML content -->
<script src="script.js"></script>
</body>
Variables:
let name = "Alex"; // Can be changed
const age = 15; // Cannot be changed
Functions:
function greet(name) {
return `Hello, ${name}!`;
}
console.log(greet("Alex")); // "Hello, Alex!"
Selecting elements:
const heading = document.querySelector('h1');
const allParagraphs = document.querySelectorAll('p');
const intro = document.getElementById('intro');
Modifying elements:
heading.textContent = "New Title";
heading.style.color = "blue";
heading.classList.add('highlighted');
Event listeners:
const button = document.querySelector('button');
button.addEventListener('click', function() {
alert('Button clicked!');
});
// Or with arrow function:
button.addEventListener('click', () => {
alert('Button clicked!');
});
Toggle dark mode:
<button id="theme-toggle">Toggle Dark Mode</button>const themeToggle = document.getElementById('theme-toggle');
const body = document.body;
themeToggle.addEventListener('click', () => {
body.classList.toggle('dark-mode');
});.dark-mode {
background-color: #1a1a2e;
color: #eee;
}
Show/hide content:
<button class="toggle-btn">Show More</button>
<div class="hidden-content" style="display: none;">
<p>This content is hidden by default!</p>
</div>const toggleBtn = document.querySelector('.toggle-btn');
const hiddenContent = document.querySelector('.hidden-content');
toggleBtn.addEventListener('click', () => {
if (hiddenContent.style.display === 'none') {
hiddenContent.style.display = 'block';
toggleBtn.textContent = 'Show Less';
} else {
hiddenContent.style.display = 'none';
toggleBtn.textContent = 'Show More';
}
});
Form handling:
<form id="contact-form">
<input type="text" id="name" placeholder="Your name" required>
<input type="email" id="email" placeholder="Your email" required>
<button type="submit">Submit</button>
</form>
<div id="form-message"></div>const form = document.getElementById('contact-form');
const formMessage = document.getElementById('form-message');
form.addEventListener('submit', (event) => {
event.preventDefault(); // Prevent page reload
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
formMessage.textContent = `Thanks, ${name}! We'll contact you at ${email}.`;
form.reset(); // Clear the form
});
---
Setup:
1. Create a GitHub account at github.com 2. Create a new repository named username.github.io (replace username with your GitHub username) 3. Upload your HTML, CSS, and JavaScript files 4. Visit https://username.github.io - your site is live!
For project sites:
1. Create any repository name 2. Upload your files 3. Go to Settings > Pages 4. Select your branch (usually main) and click Save 5. Your site is at https://username.github.io/repository-name
1. Go to netlify.com and create an account 2. Drag your project folder onto the page 3. Netlify gives you a random URL (you can customize it) 4. Any updates: just drag the folder again
Similar to Netlify, with excellent integration for more complex projects.
---
Design for phones first, then add complexity for larger screens:
/* Mobile styles (default) */
.container {
padding: 10px;
}
.card {
width: 100%;
}
/* Tablet and up */
@media (min-width: 768px) {
.container {
padding: 20px;
}
.card {
width: 48%;
}
}
/* Desktop */
@media (min-width: 1024px) {
.container {
padding: 40px;
max-width: 1200px;
margin: 0 auto;
}
.card {
width: 30%;
}
}
Always include this in your <head>:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Without it, mobile browsers will zoom out to show the full desktop site, making everything tiny.
---
alt text for images<nav>, <main>, <footer>)<head>
<title>Alex Johnson - Web Developer Portfolio</title>
<meta name="description" content="Portfolio of Alex Johnson, a student web developer specializing in HTML, CSS, and JavaScript.">
</head>
my-website/
├── index.html
├── about.html
├── projects.html
├── css/
│ └── styles.css
├── js/
│ └── script.js
└── images/
├── profile.jpg
└── project1.png
---
1. Build your personal portfolio site 2. Learn CSS Grid (complement to Flexbox) 3. Explore CSS animations and transitions 4. Practice JavaScript DOM manipulation
1. Learn a CSS framework (Tailwind, Bootstrap) 2. Study JavaScript in depth (ES6+, async/await) 3. Explore React, Vue, or Svelte 4. Understand APIs and fetching data
1. Backend development (Node.js, Python/Flask, etc.) 2. Databases (SQL, MongoDB) 3. Full-stack frameworks (Next.js, Django) 4. Deployment and DevOps
---
You've just learned the fundamentals that power billions of websites. HTML, CSS, and JavaScript are the foundation of the entire web—from simple portfolio sites to complex applications like Gmail and Facebook.
Building websites is uniquely rewarding:
Your first site won't be perfect. Professional developers cringe at their early work too. What matters is that you start, you publish, and you keep building.
Every expert was once a beginner staring at a blank HTML file, wondering where to start. Now you know. The web is waiting for what you'll create.
Welcome to web development. Start building!