How to Build Your First Website From Scratch Using HTML and CSS
The fastest way to understand the web is to build a page with nothing but a text editor and a browser. No frameworks, no builders, no templates you do not understand. Building a website from scratch with HTML and CSS means writing the structure of your page in HTML (HyperText Markup Language) and controlling how it looks with CSS (Cascading Style Sheets), then publishing those files so anyone with a link can open them. This guide walks you through the exact process I use when teaching beginners, including the parts most tutorials skip: folder structure, semantic markup, layout decisions, responsive behavior and getting the site live for free.
Quick Answer: To build your first website from scratch, create a project folder with an index.html file and a styles.css file, write semantic HTML for your header, main content and footer, link the stylesheet, style it with CSS using Flexbox for layout and media queries for mobile, then deploy the folder free on GitHub Pages or Netlify.
What Do You Actually Need to Build a Website From Scratch?
You need three things: a code editor, a modern web browser and a folder on your computer. That is genuinely the full list. HTML and CSS are plain text files that browsers read directly, so there is nothing to compile, install or configure before you see results. Anyone who tells you that you need a powerful machine, a paid course or a specific operating system to start is overcomplicating it.
Before writing code, it helps to be precise about the vocabulary. An element is a building block such as a heading or paragraph, written with opening and closing tags like <p> and </p>. An attribute adds information to an element, such as the href on a link. In CSS, a selector chooses which elements to style, a property names what you are changing, such as color, and a value sets it. If you are still deciding which tool to write in, my guide to choosing a beginner-friendly code editor compares the options in detail, but any editor with syntax highlighting will work today.
Your browser matters more than people expect. Chrome, Firefox, Edge and Safari all include developer tools, which you open by right-clicking any part of a page and choosing Inspect. This panel shows you the HTML structure, the CSS rules applied to each element and the box dimensions of everything on screen. Learning to read it early will save you hours of guessing later, because it tells you exactly why something looks the way it does.
Finally, decide what your first site is about before you open the editor. A one-page personal introduction, a page for a local club or a simple product landing page are all good choices. Having real content to place gives every HTML and CSS decision a purpose, which is how you learn the reasoning behind the code rather than memorizing syntax.
Step-by-Step: Building the Page From an Empty Folder
This sequence mirrors how professional developers start any static site. Follow it in order, saving and refreshing the browser after each step so you can see the effect of every change.
- Create the project structure. Make a folder called
my-first-site. Inside it, createindex.html,styles.cssand animagesfolder. Browsers and hosting platforms automatically treatindex.htmlas the home page, so the name matters. - Write the HTML boilerplate. Start with
<!DOCTYPE html>, then an<html lang="en">element containing<head>and<body>. In the head, add<meta charset="UTF-8">, the viewport meta tag<meta name="viewport" content="width=device-width, initial-scale=1">, a<title>and a<link rel="stylesheet" href="styles.css">. Forgetting the viewport tag is the single most common reason a beginner site looks tiny on phones. - Outline the page with semantic elements. Inside the body, add
<header>,<nav>,<main>, one or more<section>elements and a<footer>. These elements describe meaning, which helps screen readers and search engines understand your page. - Add real content. Use exactly one
<h1>for the page title,<h2>for section headings,<p>for paragraphs,<ul>for lists and<a>for links. Add images with<img src="images/photo.jpg" alt="description">, always writing meaningful alt text. - Apply a CSS reset and base styles. At the top of
styles.css, set*, *::before, *::after { box-sizing: border-box; }and remove the default body margin. Then set a readable font family, a base font size around 16 to 18 pixels and a line height near 1.5. - Build the layout with Flexbox. Make the navigation a row with
display: flex; gap: 1rem;. Center your main content withmax-width: 70ch; margin: 0 auto; padding: 1rem;so lines stay comfortable to read. - Make it responsive. Write mobile styles first, then add a media query such as
@media (min-width: 768px)to place sections side by side on larger screens. - Test, validate and publish. Run your HTML through the W3C Markup Validation Service, check the page on your phone, then deploy it.
Notice that styling comes after structure. Writing all your HTML first, even if it looks plain, forces you to think about content hierarchy. When you style as you go, you tend to choose elements based on how they look by default rather than what they mean, which creates problems later.
Choosing the Right HTML Elements and CSS Layout Tools
Most layout frustration comes from picking the wrong tool for the job. The table below maps common page needs to the element or technique that handles them cleanly, along with the mistake I see beginners make most often in each case.
| Page Need | Recommended Element or Technique | Why It Works | Common Beginner Mistake |
|---|---|---|---|
| Top navigation bar | <nav> with a <ul> and Flexbox | Lists group links logically and Flexbox aligns them in one line | Using a stack of line breaks to separate links |
| Grid of cards or photos | CSS Grid with repeat(auto-fit, minmax(250px, 1fr)) | Columns adjust automatically to screen width without media queries | Setting fixed pixel widths that overflow on phones |
| Centering a block | margin: 0 auto with a max-width, or Flexbox centering | Predictable and works at every screen size | Using large left padding values that only look centered on one screen |
| Spacing between items | The gap property in Flexbox or Grid | Spacing is applied evenly without margin collisions | Adding margins to every item and fighting double spacing |
| Main page content area | <main> containing <section> elements | Gives assistive technology and search engines a clear structure | Wrapping everything in anonymous <div> elements |
A useful rule: use Flexbox when you are arranging items in one direction, such as a row of links or a stack of buttons, and use Grid when you are controlling rows and columns at the same time. You will mix both on almost every real page, and that is normal.
Why Semantic Structure and Clean CSS Matter From Day One
This section is practitioner analysis rather than a statistic: after reviewing many first websites, the ones that are easiest to improve later are never the prettiest ones. They are the ones with clean, meaningful HTML. A page built with proper headings, landmarks and lists can be restyled completely in an afternoon. A page built from nested divs with inline styles usually has to be rewritten.
Semantic HTML also has concrete external benefits. Screen readers let users jump between headings and landmarks such as <nav> and <main>, so correct structure directly affects whether people using assistive technology can use your site. Search engines read the same structure to understand what your page is about. Google's own documentation on search fundamentals encourages clear, descriptive headings and text-based content, which semantic markup naturally provides.
On the CSS side, the habit that pays off most is consistency. Pick a small spacing scale, for example 0.5rem, 1rem, 2rem and 4rem, and use only those values. Pick two or three colors and define them once as custom properties, such as --color-primary, in a :root rule. When every value comes from a small set, your design looks intentional and changes take seconds instead of a search through hundreds of lines. If you want to see where these skills lead next, following a structured HTML, CSS and JavaScript roadmap shows how this foundation connects to interactivity and larger projects.
The cascade itself is worth understanding properly. When two rules target the same element, the browser decides which wins based on specificity and source order. Class selectors beat element selectors, ID selectors beat classes, and later rules beat earlier ones with equal specificity. Styling mostly with classes keeps specificity low and predictable, which is why experienced developers avoid ID selectors for styling.
Common Mistakes When Building Your First Website and How to Avoid Them
The same handful of mistakes show up in almost every first project. Each one is easy to fix once you know to look for it.
- Broken file paths. If your styles or images do not load, the path is almost always wrong. Paths are relative to the HTML file, so
images/photo.jpgonly works if the images folder sits next toindex.html. File names are also case-sensitive on most web servers, soPhoto.JPGandphoto.jpgare different files once deployed. - Multiple h1 elements chosen for size. Headings define structure, not font size. If you want bigger text, change it with CSS rather than picking a higher-level heading.
- Fixed widths everywhere. Setting
width: 1200pxon a container guarantees horizontal scrolling on phones. Usemax-widthwith percentage or flexible units instead. - Images that break the layout. Add
img { max-width: 100%; height: auto; display: block; }to your base styles so images never overflow their containers. - Copying CSS you do not understand. Pasting a snippet that works is fine once. Pasting ten creates a stylesheet you cannot debug. Before keeping any copied rule, remove each property one at a time and observe what changes.
- Ignoring contrast and font size. Light grey text on white looks elegant in a mockup and becomes unreadable on a phone in sunlight. Check your color pairs with a contrast checker against the WCAG guidelines.
- Never validating. An unclosed tag can silently break the layout of everything after it. The W3C validator catches these instantly and is free.
Real-World Walkthrough: From Blank Folder to Live Site
Here is how a realistic first build plays out, using a one-page site for a fictional neighborhood book club as the example. The goal is a page with a header, a short introduction, a list of upcoming meetings, a gallery of book covers and a contact section.
Session one: structure. Write the full HTML before any CSS. The header holds the club name as the <h1> and a <nav> with links to #meetings, #books and #contact. Each section gets a matching id so those links jump down the page. The meeting list uses a <ul> where each item contains a date in a <time> element and the book title. The contact section uses a simple mailto link rather than a form, because forms need a backend or third-party service to actually send messages.
Session two: base styling. Add the box-sizing reset, set the font stack, define three color custom properties and a spacing scale. Style links so they are clearly distinguishable from body text and have a visible focus outline for keyboard users. At this stage the page should already be comfortable to read on a phone.
Session three: layout. Turn the navigation into a flex row that wraps on narrow screens with flex-wrap: wrap. Build the book gallery with Grid using the auto-fit pattern from the table above, so it shows one column on phones and three or four on desktops without a single media query. Add one media query at 768 pixels to place the introduction text beside an image.
Session four: polish and test. Open developer tools, switch to the device toolbar and test common phone widths. Tab through the page with your keyboard to confirm every link is reachable and visibly focused. Run the validator, fix any errors and compress your images. Large unoptimized photos are the usual reason a simple static site loads slowly.
Session five: deploy. Create a free GitHub account, make a new repository, upload your files and enable GitHub Pages in the repository settings. Within a few minutes your site is live at a public URL. Alternatively, Netlify lets you drag the folder onto its dashboard to publish it. Both options are free for static sites like this one.
Use this checklist before calling the site finished: viewport meta tag present, one h1, logical heading order, alt text on every meaningful image, no horizontal scrolling at narrow widths, visible focus states, validator passes, images compressed and every link tested.
Key Takeaways
- A first website needs only a code editor, a browser and a folder containing an index.html file and a stylesheet.
- Writing complete semantic HTML before adding CSS produces cleaner structure and makes the site far easier to restyle later.
- Flexbox handles one-directional layouts like navigation bars, while CSS Grid handles two-dimensional layouts like card galleries.
- The viewport meta tag, flexible widths and responsive images prevent the most common mobile layout failures.
- Static HTML and CSS sites can be published free on GitHub Pages or Netlify within minutes of finishing the code.
Frequently Asked Questions
Can I build a website with only HTML and CSS?
Yes. HTML and CSS alone are enough for informational sites such as portfolios, landing pages, restaurant menus and event pages. You only need JavaScript for interactive behavior like toggling menus or validating forms, and you need a backend or third-party service for features such as sending form submissions or storing user data.
How long does it take to build a first website from scratch?
A simple one-page site usually takes a beginner a few focused sessions spread over a weekend or a week. The first page is slow because you are learning syntax and debugging paths. Your second and third pages go much faster because the structure, reset styles and layout patterns can be reused directly.
Do I need to pay for hosting to publish an HTML and CSS website?
No. Static sites made of HTML, CSS and images can be hosted free on GitHub Pages, Netlify, Cloudflare Pages and similar platforms. You only need to pay if you want a custom domain name, which is an annual registration fee from a domain registrar, not a hosting cost.
Should I learn Flexbox or CSS Grid first?
Learn Flexbox first. It solves the most common beginner layouts, such as navigation bars, centered content and rows of buttons, with fewer concepts. Once you are comfortable aligning items in one direction, CSS Grid becomes easy to pick up for galleries, card layouts and full page structures with rows and columns.
Why is my CSS file not working on my HTML page?
The most common cause is an incorrect path in the link tag. Confirm the href matches the stylesheet's exact file name and location, including capitalization, and that the link sits inside the head element. Then open developer tools, check the Network tab for a failed request, and hard-refresh to clear cached styles.
Is it better to use a website builder instead of coding from scratch?
It depends on your goal. Builders are faster if you only need a site running quickly. Coding from scratch is better if you want to learn web development, because it teaches how pages actually work. Many developers start by hand-coding one small site, then choose tools based on real understanding.
Conclusion
The most important decision on your first website is not which colors or fonts to use. It is committing to write meaningful HTML structure first and treating CSS as a layer on top of it. That one habit makes your page accessible, search-friendly and easy to change, and it is the same discipline professional developers rely on for large projects. Once your first page is live, the best next step is to repeat the process on something slightly harder, and these weekend projects that build on these basics give you a clear set of builds to tackle next.




