Learn HTML and CSS: Build Your First Website Step by Step

By the Librava editors · Updated 2026-10-26

If you have ever wanted your own website for a club, a small business or a hobby, but felt put off by jargon, you are in the right place. To make a website with HTML and CSS, you create a folder on your computer, write your page content in an HTML file, add a separate CSS file for colors and layout, test it in your browser and then upload the folder to a free hosting service.

That is the whole process, and you can do every step with free tools. This guide walks you through each stage in plain English. You need no coding experience, only a computer and some patience with the odd missing bracket.

What you need before you start

A website is simply a folder of files sitting on a computer that is connected to the internet. Your browser fetches those files and turns them into the page you see. So you can build and test the whole site on your own computer first.

Here is your starter kit:

  • A code editor. This is a free program for writing plain text code. Search for a free code editor with good reviews from a trustworthy source. It will color your code, number the lines and keep things neatly indented.
  • A web browser you already use, for testing.
  • A project folder, for example a folder called websites in your Documents, with a folder inside it called my-first-site.
  • An images folder inside your project folder for pictures.

Never write code in a word processor. It quietly adds hidden formatting and swaps straight quotes for curly ones, which breaks your page. Also turn on visible file extensions in your computer's file settings, so you can tell index.html apart from index.html.txt.

Name every file in lowercase, with hyphens instead of spaces, such as about-us.html or team-photo.jpg. Many web servers treat Photo.jpg and photo.jpg as two different files, so a page that works on your computer can lose its images once it goes online.

How to write your first HTML page

HTML (HyperText Markup Language) labels your content so the browser knows what each piece is: a heading, a paragraph, a list, a link or an image. CSS (Cascading Style Sheets) then decides how those pieces look.

Create a file called index.html in your project folder. The home page is always called index.html, because servers look for that name automatically. Every page uses the same basic skeleton, in this order:

  1. <!DOCTYPE html> on the very first line, which tells the browser this is a modern page.
  2. <html lang="en"> wrapping everything, so screen readers and translation tools know the language.
  3. A <head> section holding <meta charset="UTF-8">, the viewport line <meta name="viewport" content="width=device-width, initial-scale=1"> and a <title> for the browser tab.
  4. A <body> section holding everything visible, such as <h1>Hello, I made this</h1> and a <p> paragraph.
  5. Closing tags in reverse order: </body> and then </html>.

Save the file, then double-click it in your file manager. It opens in your browser, and you have a working web page. From now on you will repeat a simple loop: edit the code, save, refresh the browser. If nothing changes, check that you saved and that the browser shows the file you are editing.

Look inside: HTML and CSS for Beginners Made Simple

HTML and CSS for Beginners Made Simple by Leo Parfitt, preview page 1
HTML and CSS for Beginners Made Simple · preview 1
HTML and CSS for Beginners Made Simple by Leo Parfitt, preview page 2
HTML and CSS for Beginners Made Simple · preview 2
HTML and CSS for Beginners Made Simple by Leo Parfitt, preview page 3
HTML and CSS for Beginners Made Simple · preview 3
HTML and CSS for Beginners Made Simple by Leo Parfitt, preview page 4
HTML and CSS for Beginners Made Simple · preview 4

Read the free sample →

Add headings, links, images and lists

Most tags come in pairs, an opening tag and a closing tag with a slash, and whatever opens last must close first. A few tags, such as <img> and <meta>, have no closing tag at all.

Headings and text

Use one <h1> per page for the main title, then <h2> for sections and <h3> for subsections. Do not skip levels, and do not pick a heading because of its size. You will control size with CSS later. People who use screen readers often jump from heading to heading, so a logical order matters.

Links and images

A link uses the <a> tag with an href attribute, such as <a href="about.html">About us</a>. For pages and pictures inside your own site, use relative paths like images/shop-front.jpg, never a path that points to your own computer's drive. Write link text that makes sense on its own, so "Read our opening hours" rather than "Click here."

An image uses <img src="images/bread.jpg" alt="A basket of fresh rolls on the counter">. The alt text describes the picture for people who cannot see it and appears if the image fails to load. Resize photos before you add them. A photo straight from a phone can be several megabytes, while a picture for a web page rarely needs to be wider than about 1,200 to 2,000 pixels.

Lists

Use <ul> for bullet lists and <ol> for numbered steps, with each item inside <li>. Lists are also the standard way to build a menu.

How to style your page with CSS

Create a second file called styles.css in the same folder, then link it inside the <head> of every page with <link rel="stylesheet" href="styles.css">. Keeping all your styles in one external file means a single change updates every page on the site.

A CSS rule has three parts: a selector (which element), a property (what to change) and a value (how). For example, body { font-family: Georgia, serif; color: #222222; } sets the font and text color for the whole page. Each property ends with a semicolon, and each rule sits inside curly braces.

SelectorWhat it targetsExample use
pEvery paragraphLine height and size
.cardElements with class="card"A boxed panel
nav aLinks inside the menuMenu colors
a:hover, a:focusLinks being pointed at or tabbed toVisible highlight

Two habits save hours. First, CSS uses US spelling, so color and center work while colour and centre are silently ignored. Second, when a rule does nothing, check the line above it for a missing semicolon or brace. Right-click any part of your page and choose Inspect to open the browser's developer tools, which show exactly which styles apply to that spot.

For text, a size of 1rem is the browser's default, often 16 pixels. A line height of about 1.5 and a line length of roughly 60 to 75 characters make text comfortable to read.

Control spacing and layout

Every element on a page is a box. Inside is the content, then padding (space inside the border), then the border, then margin (space outside).

Start every stylesheet with the border-box fix, which tells the browser to include padding and border in an element's width: *, *::before, *::after { box-sizing: border-box; }. Without it, a box set to 300 pixels wide with 20 pixels of padding ends up 340 pixels wide, and layouts break in confusing ways.

To make a readable, centered page column, give your main content a max-width, for example 70rem, plus margin: 0 auto and some side padding. On a wide screen the column sits in the middle, and on a narrow screen it shrinks to fit.

Flexbox for rows

Flexbox lines items up in a row or column. Put display: flex on a container, such as your menu list, and its children sit side by side. Add gap: 1rem for even spacing, justify-content: space-between to push a site name and menu to opposite ends, and flex-wrap: wrap so items move to a new line on small screens.

Grid for two-dimensional layouts

CSS Grid handles rows and columns together, which suits photo galleries and full page layouts. A single line does a lot of work: grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); creates as many columns as fit, each at least 15rem wide, sharing the leftover space evenly. A good rule of thumb is Flexbox for a single row of things, Grid for a pattern of rows and columns.

How to make your website work on phones

Many visitors will see your site on a phone first, so build for small screens from the start, an approach called mobile-first design.

  1. Include the viewport meta tag on every page. Without it, phones shrink a desktop-sized page down until the text is unreadable.
  2. Write your base CSS for a narrow screen: one column, full-width images, comfortable padding.
  3. Add media queries for wider screens, such as @media (min-width: 48em) { ... }, and put your two- or three-column layouts inside them.
  4. Give images max-width: 100% and height: auto so they never spill past the edge of the screen.
  5. Let your menu wrap or stack on small screens instead of squeezing.

Test as you go. Your browser's developer tools include a device view that shows the page at phone widths, and nothing beats opening the page on a real phone once it is online. If the page scrolls sideways on a phone, look for a fixed width or an oversized image.

Make your site accessible to everyone

Accessibility means people can use your site whatever their eyesight, hearing, movement or device. It costs almost nothing if you build it in from the start.

  • Use meaningful HTML: <header>, <nav>, <main> and <footer> instead of anonymous boxes.
  • Keep headings in a logical order with a single <h1>.
  • Write useful alt text, and use an empty alt="" for purely decorative images.
  • Check color contrast. Normal body text should reach a contrast ratio of at least 4.5 to 1 against its background. Free online contrast checkers will test your colors.
  • Never use color alone to carry meaning, such as red text for required fields with no other label.
  • Keep a visible focus style on links and buttons so keyboard users can see where they are.
  • Give every form field a <label>.

Then do two quick tests. Unplug the mouse, or just ignore it, and press Tab through the whole page to make sure you can reach and see every link. Then zoom the browser to 200 percent and check that nothing overlaps or disappears.

How to publish your website for free

For a site made of plain HTML and CSS files, free hosting is easy to find. There are free static hosting services built for exactly this kind of site, and free code sharing sites that can also publish a folder as a website. Most include HTTPS (the padlock) and give you a free web address. Free tiers have limits and terms can change, so read them first.

Before you upload, run through this checklist:

  • index.html sits at the top level of the folder, not inside another folder.
  • All file names are lowercase with hyphens, and the capital letters in every path match the real file names exactly.
  • Every link and image works on your own computer.
  • Your HTML and CSS have been through a free online validator. Fix the first error, then re-check, because one missing tag can cause a chain of errors.
  • There are no passwords, private phone numbers or personal notes anywhere, including comments. Anyone can view the source of a page.
  • Every image is yours or properly licensed, and people in photos have agreed to appear.

Then create an account, choose to make a new site, and upload the contents of your project folder so that index.html, styles.css and the images folder sit side by side at the root. Open the live address on a computer and a phone, and click everything again.

A custom domain name, such as your club's own .com or .org.uk address, is rented yearly from a registrar rather than bought forever. Check the renewal price as well as the first-year price, and turn on auto-renew if you plan to keep it.

To update the site later, edit the copy on your computer, test it, then upload again. Keep backups in at least two other places, because your host is not a backup.

Learn HTML And CSS

As you learn HTML and CSS, build a page about something you know. Add a heading, two paragraphs, an image with useful alternative text and a link. Then use a separate stylesheet to set readable spacing and a comfortable line length. Resize the window and test every link. This gives you a complete project to improve instead of a folder of disconnected examples.

Frequently asked questions

Can I make a website with just HTML and CSS?

Yes. HTML and CSS alone are enough for a complete, attractive website such as a personal page, a club site, a portfolio or a small business site with several pages. JavaScript adds interactive behavior, like pop-up menus or live form checks, and is a sensible next step once you are comfortable, but you do not need it to build and publish a useful site.

How long does it take to learn HTML and CSS?

Most beginners can build a simple one-page site within a weekend of practice and a tidy multi-page, phone-friendly site within a few weeks of regular short sessions. Getting confident with layout tools like Flexbox and Grid usually takes longer. Short, frequent practice works better than one long session, and building small real projects teaches more than reading alone.

Do I need to pay for software to code a website?

No. A free code editor, the browser you already have and a free static hosting service cover everything you need to build and publish a basic site. The only cost you might choose later is a custom domain name, which is rented yearly from a registrar. Free hosting has usage limits, but they are usually generous for small sites.

What is the difference between HTML and CSS?

HTML describes what your content is: headings, paragraphs, lists, links, images and page sections. CSS describes how that content looks: colors, fonts, spacing and layout. You can take the same HTML and make it look completely different by changing only the CSS, which is why keeping your styles in one separate stylesheet makes a site much easier to update.

How do I make my HTML website mobile friendly?

Add the viewport meta tag to the head of every page, write your base styles for a narrow single-column screen, and use media queries to add wider layouts for larger screens. Give images a max-width of 100 percent so they shrink to fit. Test in your browser's device view and on a real phone, checking that nothing scrolls sideways.

Your first step today is small: install a free code editor, create a my-first-site folder and write a five-line index.html with one heading and one paragraph. Open it in your browser, change a word, save and refresh. Once that loop feels natural, add a stylesheet, then a second page, and you will be closer to a published site than you think. If you like learning with a book beside you, HTML and CSS for Beginners Made Simple follows this same path with cheat sheets and four practice projects.

More free guides

All free guides →