How to create a website using HTML and CSS step-by-step beginner guide with coding example

How to Create a Website Using HTML and CSS (Step-by-Step Beginner Guide 2026)

Why Learn to Create a Website Using HTML and CSS?

Prerequisites

Code Editor

Web Browser

What is HTML?

<h1>Welcome to My Website</h1>
<p>This is my first webpage.</p>

What is CSS?

Step-by-Step Guide to Create a Website Using HTML and CSS

Step 1: Create Your Website Project Folder

On Windows

my-website

Step 2: Open the Folder in Visual Studio Code

Step 3: Create Website Files & Folder Structure

Step 4: Add Reusable Header (components/header.html)

<header>
  <h1>My Website</h1>

  <!-- Hamburger Button for Mobile -->
  <button id="menu-toggle"></button>

  <nav id="nav-links">
    <a href="index.html">Home</a>
    <a href="about.html">About</a>
    <a href="contact.html">Contact</a>
  </nav>
</header>

Step 5: Add Reusable Footer (components/footer.html)

<footer>
  <p>© 2026 My Website</p>
</footer>

Step 6: Add Your CSS Styling (style.css)

/* Reset default margins and paddings */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Make sure html and body fill viewport */
html, body {
  height: 100%;
}

/* General Styles */
body {
  font-family: Arial, sans-serif;
  margin: 0;
  min-height: 100vh;       /* Full viewport height */
  display: flex;
  flex-direction: column;  /* Stack children vertically */
}

/* Header, main content, and footer structure */
header {
  background: #333;
  color: white;
  text-align: center;
  padding: 20px;
  flex-shrink: 0; /* Prevent shrinking */
}

nav {
  background: #555;
  text-align: center;
  padding: 10px;
}

nav a {
  color: white;
  margin: 10px;
  text-decoration: none;
  font-weight: bold;
}

nav a:hover {
  color: yellow;
}

/* The main section grows to fill available space */
section {
  padding: 40px;
  flex-grow: 1;  /* Push footer down */
}

footer {
  background: #333;
  color: white;
  text-align: center;
  padding: 15px;
  flex-shrink: 0; /* Prevent shrinking */
  margin-top: auto; /* Push footer to bottom */
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
  nav a {
    display: block;
    margin: 10px 0;
  }

  section {
    padding: 20px;
  }

  header, footer {
    text-align: center;
    padding: 15px;
  }
}

/* Smaller devices */
@media (max-width: 480px) {
  h1 { font-size: 24px; }
  h2 { font-size: 20px; }
  p { font-size: 16px; }
}

img {
  max-width: 100%;
  height: auto;
}

/* Hamburger Button */
#menu-toggle {
  display: none; /* Hidden on desktop */
  background: #555;
  color: white;
  border: none;
  font-size: 24px;
  padding: 10px;
  cursor: pointer;
}

/* Mobile Navigation */
@media (max-width: 768px) {
  #menu-toggle { display: block; }
  #nav-links { display: none; text-align: center; background: #555; }
  #nav-links.show { display: block; }
  #nav-links a { display: block; margin: 10px 0; }
}

#menu-toggle:hover {
  background: #333;
  color: yellow;
}

Step 7: Create the Home Page (index.html)

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>My Website - Home</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>

<!-- Header -->
<div id="header"></div>

<!-- Main Content -->
<section>
  <h2>Welcome</h2>
  <p>This is the home page of my website built using HTML and CSS.</p>
</section>

<!-- Footer -->
<div id="footer"></div>

<!-- JS: Load header/footer and toggle mobile menu -->
<script>
function loadHTML(id, url, callback){
  fetch(url)
    .then(response => response.text())
    .then(data => {
      document.getElementById(id).innerHTML = data;
      if(callback) callback();
    });
}

// Load header with mobile menu
loadHTML('header', 'components/header.html', () => {
  const menuButton = document.getElementById('menu-toggle');
  const navLinks = document.getElementById('nav-links');
  if(menuButton && navLinks){
    menuButton.addEventListener('click', () => {
      navLinks.classList.toggle('show');
    });
  }
});

// Load footer
loadHTML('footer', 'components/footer.html');
</script>

</body>
</html>

Step 8: Create the About Page (about.html)

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>My Website - About</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>

<div id="header"></div>

<section>
  <h2>About This Website</h2>
  <p>This website is a beginner project created using HTML and CSS.</p>
  <p>It demonstrates how multiple pages can share the same header and footer.</p>
</section>

<div id="footer"></div>

<script>
function loadHTML(id, url, callback){
  fetch(url)
    .then(response => response.text())
    .then(data => {
      document.getElementById(id).innerHTML = data;
      if(callback) callback();
    });
}

loadHTML('header', 'components/header.html', () => {
  const menuButton = document.getElementById('menu-toggle');
  const navLinks = document.getElementById('nav-links');
  if(menuButton && navLinks){
    menuButton.addEventListener('click', () => {
      navLinks.classList.toggle('show');
    });
  }
});

loadHTML('footer', 'components/footer.html');
</script>

</body>
</html>

Step 9: Create the Contact Page (contact.html)

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>My Website - Contact</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>

<div id="header"></div>

<section>
  <h2>Contact Information</h2>
  <p>Email: example@email.com</p>
  <p>Phone: +91 9876543210</p>
</section>

<div id="footer"></div>

<script>
function loadHTML(id, url, callback){
  fetch(url)
    .then(response => response.text())
    .then(data => {
      document.getElementById(id).innerHTML = data;
      if(callback) callback();
    });
}

loadHTML('header', 'components/header.html', () => {
  const menuButton = document.getElementById('menu-toggle');
  const navLinks = document.getElementById('nav-links');
  if(menuButton && navLinks){
    menuButton.addEventListener('click', () => {
      navLinks.classList.toggle('show');
    });
  }
});

loadHTML('footer', 'components/footer.html');
</script>

</body>
</html>

Step 10: Run Website

Create a website using HTML and CSS mobile view

Tip: Use Live Server Extension

Common Mistakes Beginners Make

1. Incorrect file names

Index.html
index.HTML
index.html

2. Forgetting to link CSS

<link rel="stylesheet" href="style.css">

3. Broken navigation links

Conclusion

🚀 Subscribe for Tech Updates

📧

👤

We respect your privacy. Unsubscribe anytime.

Leave a Comment

Your email address will not be published. Required fields are marked *