DEV Community

Cover image for How to Build Your First Website from Scratch
Pixel Mosaic
Pixel Mosaic

Posted on

How to Build Your First Website from Scratch

Want to create your own website but don't know where to start? This guide will walk you through the entire process—from a blank folder to a live website on the internet.

Why Build a Website from Scratch?

Building a website from scratch is one of the fastest ways to learn web development. Instead of relying on templates or website builders, you'll understand:

  • How websites actually work
  • HTML, CSS, and JavaScript fundamentals
  • Responsive design principles
  • How to publish your work online
  • Skills that employers and clients value

The best part? You can build your first website in a single weekend.

What You'll Need

Before we start, make sure you have:

A computer
A code editor (VS Code is a popular choice)
A modern browser (Chrome, Firefox, Edge)
Curiosity and patience

That's it.

Step 1: Create Your Project Folder

Create a new folder called:

my-first-website
Enter fullscreen mode Exit fullscreen mode

Inside it, create three files:

index.html
style.css
script.js
Enter fullscreen mode Exit fullscreen mode

Your project structure should look like:

my-first-website/
│
├── index.html
├── style.css
└── script.js
Enter fullscreen mode Exit fullscreen mode

Step 2: Build the HTML Structure

Open index.html and add:

<!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>
    <link rel="stylesheet" href="style.css">
</head>
<body>

    <header>
        <h1>Welcome to My First Website</h1>
        <p>I built this from scratch!</p>
    </header>

    <button id="btn">Click Me</button>

    <script src="script.js"></script>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

This creates the basic structure of your webpage.

Step 3: Add Some Style with CSS

Open style.css:

body {
    font-family: Arial, sans-serif;
    text-align: center;
    background: #f4f4f4;
    padding: 50px;
}

header {
    background: white;
    padding: 30px;
    border-radius: 10px;
}

button {
    margin-top: 20px;
    padding: 12px 20px;
    border: none;
    background: #0077ff;
    color: white;
    cursor: pointer;
    border-radius: 5px;
}
Enter fullscreen mode Exit fullscreen mode

Now your website looks much more professional.

Step 4: Make It Interactive with JavaScript

Open script.js:

const button = document.getElementById("btn");

button.addEventListener("click", () => {
    alert("Congratulations! Your website is working.");
});
Enter fullscreen mode Exit fullscreen mode

When users click the button, they'll see a popup message.

Step 5: Test Your Website

Open index.html in your browser.

You should see:

  • A heading
  • A short description
  • A clickable button

Click the button.

If the popup appears, you've just built your first interactive website.

Congratulations!

Step 6: Make It Mobile-Friendly

Most visitors browse on smartphones.

Add this to your CSS:

@media (max-width: 768px) {
    body {
        padding: 20px;
    }

    h1 {
        font-size: 28px;
    }
}
Enter fullscreen mode Exit fullscreen mode

Your site now adapts to smaller screens.


Step 7: Publish It for Free

You can host your website for free using GitHub Pages.

Quick Steps

  1. Create a GitHub account
  2. Upload your project
  3. Go to Settings → Pages
  4. Select your branch
  5. Click Save

Your site will be live within minutes.

Now anyone can access it through a public URL.

Common Beginner Mistakes

Forgetting to Link CSS

<link rel="stylesheet" href="style.css">
Enter fullscreen mode Exit fullscreen mode

Wrong File Names

Make sure filenames match exactly.

Not Checking Browser Console

Open:

F12 → Console
Enter fullscreen mode Exit fullscreen mode

It helps identify errors quickly.

What's Next?

Once you've built your first website, try adding:

  • Navigation menus
  • Contact forms
  • Dark mode
  • Animations
  • Image galleries
  • APIs
  • Portfolio projects

Each project will teach you something new.

Final Thoughts

Every professional web developer started with a simple HTML page.

The difference between beginners and experts isn't talent—it's consistency.

Build small projects. Break things. Fix them. Repeat.

Six months from now, you'll be amazed at how much you've learned.

Discussion

What was the first website you ever built?

  • A portfolio?
  • A blog?
  • A landing page?
  • Something completely random?

Share your answer in the comments

Top comments (0)