DEV Community

Chloe Decker
Chloe Decker

Posted on

How to Build an SEO-Friendly Static Website Using HTML and CSS

Building a website doesn't always require WordPress, React, or a complicated content management system. Sometimes, a simple HTML and CSS website is all you need.

Static websites are especially useful for portfolios, small business websites, landing pages, documentation, and informational projects. They are generally easy to maintain, inexpensive to host, and can load quickly when built properly.

But there's something important that developers sometimes overlook: a website that looks good isn't necessarily optimized for search engines.

Search engine optimization (SEO) should be considered during development, not added only after the website goes live.

In this tutorial, we'll build the foundation of a simple SEO-friendly static website using HTML and CSS. We'll also look at semantic HTML, metadata, canonical URLs, image optimization, structured data, and technical checks that can help search engines understand your pages.

1. Start With a Clean Project Structure

Before writing code, organize your project files.

For a basic static website, you might use this structure:

my-static-website/
│
├── index.html
├── about.html
├── contact.html
├── robots.txt
├── sitemap.xml
│
├── css/
│ └── style.css
│
└── images/
├── hero.webp
└── favicon.png

This structure keeps the project manageable as the website grows.

The homepage uses index.html, while other pages have separate HTML files. Styles live in an external CSS file, and images are kept in their own folder.

You don't need a complicated architecture to create a useful website. Clear organization makes future updates, debugging, and maintenance easier.

2. Create an SEO-Friendly HTML Document

Every page should begin with a proper HTML structure.

Here's an example of a homepage for a fictional London travel website:

<!DOCTYPE html>


content="width=device-width, initial-scale=1.0">

London Travel Guide | Places to Visit & Tips

content="Explore London attractions, travel tips,
local transport options and practical guides
to help plan your visit.">

href="https://example.com/">



Home
About
Contact


Explore London With Practical Travel Guides

<p>
  Discover places to visit, transport options,
  and helpful tips for planning a London trip.
</p>

© 2026 London Travel Guide


This simple structure includes several important SEO and accessibility features.

The lang attribute identifies the page language. The viewport tag allows the layout to adapt to different devices. The title and description explain the page's content, while the canonical tag identifies the preferred URL.

The page also uses semantic HTML elements such as header, nav, main, and footer.

These elements make the document easier to understand for browsers, assistive technologies, and developers.

Important: Replace example.com with your actual website domain and update the canonical URL for each page.

3. Write Unique Title Tags and Meta Descriptions

The HTML title is one of the first elements you should consider when building a page.

A title should accurately describe the content and distinguish the page from other pages on the website.

For example:

Greenwich London Travel Guide | What to See

A suitable meta description might look like this:

content="Explore Greenwich in London, including
historic attractions, riverside walks,
Greenwich Market and transport tips.">

Try to avoid repeating the same title and description across multiple pages.

A homepage, destination guide, and contact page should not all use identical metadata.

Remember that Google may generate its own search-result title or snippet based on the page content. The title and meta description are helpful signals, not guarantees of exactly what will appear in search results.

4. Use Semantic HTML and a Clear Heading Structure

Headings help visitors understand how a page is organized.

They also provide context about the topics discussed in different sections.

Here's an example:

How to Explore Greenwich in One Day


Getting to Greenwich


Greenwich is accessible by train, DLR and boat.



Places to Visit

<h3>Cutty Sark</h3>
<p>Discover the historic sailing ship.</p>

<h3>Greenwich Park</h3>
<p>Enjoy views across the Thames and London.</p>

Use one main heading that clearly identifies the page's primary topic. Additional headings should follow a logical hierarchy.

A page does not need dozens of headings or repeated keywords to be optimized.

Write headings that help people navigate the content naturally.

5. Make Your Website Mobile-Friendly With CSS

A website should work comfortably on phones, tablets, and desktop computers.

CSS makes it possible to create responsive layouts without relying on heavy frontend frameworks.

Here's a simple starting stylesheet:

  • { box-sizing: border-box; }

body {
margin: 0;
font-family: Arial, sans-serif;
line-height: 1.6;
color: #222;
background: #fff;
}

header {
background: #102a43;
padding: 20px;
}

nav {
display: flex;
justify-content: center;
flex-wrap: wrap;
gap: 20px;
}

nav a {
color: #fff;
text-decoration: none;
}

main {
max-width: 1100px;
margin: auto;
padding: 24px;
}

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

@media (max-width: 768px) {
main {
padding: 16px;
}

nav {
flex-direction: column;
align-items: center;
gap: 12px;
}
}

This stylesheet provides readable text, responsive images, a flexible navigation layout, and a comfortable maximum content width.

For real projects, remember to check keyboard navigation, text contrast, and focus indicators as well.

Responsive design is not just about making elements fit a smaller screen. It should also make the website easy to use.

6. Optimize Images Without Sacrificing Quality

Images are important for many websites, particularly travel, hospitality, and local business projects.

However, unnecessarily large image files can slow down the page.

A useful approach is to choose appropriate image dimensions, compress files, and use modern formats such as WebP or AVIF where supported.

For example:

src="/images/greenwich-park.webp"
alt="View of Greenwich Park overlooking London"
width="1200"
height="800"
loading="lazy">

There are several useful details in this example.

The alt attribute describes the image for users who cannot see it. The width and height attributes help browsers reserve space before the image finishes loading.

The loading="lazy" attribute tells browsers they can defer loading an image until it is closer to the visible area.

Avoid automatically applying lazy loading to the main image that visitors see immediately when opening the page. Prioritizing that image can improve the initial loading experience.

It's also worth using descriptive filenames.

For example, greenwich-park-view.webp is easier to understand than IMG_9847.webp.

Descriptive filenames and alternative text help make images more accessible and provide useful context to search engines.

7. Add Internal Links That Help Visitors Navigate

Internal linking is an important part of website architecture.

It connects related pages and makes useful content easier to discover.

For example, imagine a travel website with separate pages for Greenwich, Camden, and London transport.

A Greenwich article could include links to related guides:

Planning to explore more of London? Read our London transport guide before your next trip.

The link text clearly explains what visitors can expect to find.

Avoid vague anchor text such as "click here" when a descriptive phrase would be more useful.

Also, use real HTML links with an href attribute rather than relying entirely on JavaScript click handlers.

Search engines can discover ordinary HTML links more reliably.

8. Include Practical Content for Real Visitors

Technical SEO is important, but it cannot replace useful content.

A website should answer the questions people actually have.

For example, a travel or transport website should help visitors find the information they need without unnecessary navigation. One example is London Airport Taxi, a website that provides airport transfer information, destination-specific pages, and an online booking system.

From a technical SEO perspective, websites like this benefit from clear navigation, descriptive URLs, internal linking, mobile-friendly layouts, and structured data. These elements help search engines understand the content while making it easier for visitors to find relevant information.

For developers building similar websites, the useful lesson is to organize content around genuine visitor tasks rather than simply creating multiple pages targeting variations of the same keyword.

A page discussing airport transportation should help readers understand their options. A pricing page should explain what affects the cost. A booking page should make the next step clear.

Good information architecture helps visitors complete these tasks and gives search engines a better understanding of the website's purpose.

9. Add Canonical URLs to Avoid Confusion

The same content can sometimes be accessible through multiple URLs.

This might happen when a website uses different URL parameters or when both an old and new page remain accessible.

Canonical tags help indicate which URL you prefer search engines to treat as the primary version.

Example:

href="https://example.com/greenwich-guide.html">

Place this tag inside the HTML .

Each main page should normally point to its own preferred URL, unless it is intentionally a duplicate of another page.

For example, the Greenwich page should not accidentally declare the homepage as its canonical URL.

It's also important to understand that canonical tags are signals rather than commands. Google can select a different canonical if other signals suggest that another URL is more appropriate.

When permanently moving a page, a server-side 301 redirect is often the better approach.

10. Create a Simple XML Sitemap

A sitemap helps search engines discover important URLs on your website.

For a small static website, you can create a file named sitemap.xml in the root directory.

Example:

<?xml version="1.0" encoding="UTF-8"?>


https://example.com/


https://example.com/about.html


https://example.com/contact.html

Use your actual website domain and include URLs that you want search engines to discover and index.

Avoid adding broken pages, redirects, or URLs that are intentionally excluded from search.

For a small website, maintaining the sitemap manually may be enough. For larger projects, automating sitemap generation can save time.

A sitemap does not guarantee indexing, but it provides an additional discovery mechanism.

11. Configure robots.txt Correctly

The robots.txt file provides crawling instructions to compliant search engine crawlers.

For a simple public website, the file may look like this:

User-agent: *
Allow: /

Sitemap: https://example.com/sitemap.xml

This tells compliant crawlers they are allowed to access the website and identifies the sitemap location.

However, robots.txt is not a security mechanism, and it should not be used to hide sensitive information.

It also does not guarantee that a URL will remain out of search results.

If a page should not appear in search results, use an appropriate noindex directive while allowing crawlers to access the page.

For confidential information, proper authentication and access controls are necessary.

12. Add Structured Data When Appropriate

Structured data provides machine-readable information about the content of a page.

For example, a business homepage may include Organization structured data to describe the organization.

Here's a minimal JSON-LD example for a fictional website:

{
"@context": "https://schema.org",
"@type": "Organization",
"name": "Example Travel Guides",
"url": "https://example.com/"
}

Place this inside the HTML document, normally in the or .

For a real business, use accurate information about the organization and select the appropriate Schema.org type.

For local businesses, a more specific LocalBusiness subtype may be suitable.

Do not add properties that are misleading, unsupported, or unrelated to the page.

Structured data can help search engines understand certain details, but adding markup does not guarantee rich results or higher rankings.

13. Deploy Your Static Website

Once the HTML and CSS are ready, the website needs to be deployed.

Popular hosting options for static sites include GitHub Pages, Cloudflare Pages, and Netlify.

The basic process is similar across many platforms.

First, upload your website files or connect your code repository. Then configure the published directory and domain.

Once the deployment finishes, open the live website and check that all pages, stylesheets, images, and links work correctly.

If you're using a custom domain, configure DNS and HTTPS according to your hosting provider's instructions.

Also verify that your canonical URLs reference the actual public domain rather than a temporary development address.

14. Test Your Website Before and After Launch

A website should be tested before publication and monitored afterwards.

Useful tools include Google Search Console, PageSpeed Insights, Chrome DevTools, and the Rich Results Test.

Google Search Console helps you understand indexing, search performance, and which URLs Google has selected as canonical.

PageSpeed Insights provides performance information, including Core Web Vitals measurements where field data is available.

Chrome DevTools can help identify layout problems, large resources, and unexpected network requests.

The Rich Results Test checks supported structured data implementations.

A practical testing workflow should include:

Confirming that pages return successful HTTP responses.

Testing navigation and internal links.

Checking the mobile layout.

Verifying canonical URLs.

Confirming that important pages are crawlable.

Testing image dimensions and loading.

Reviewing accessibility and keyboard navigation.

Submitting the sitemap in Google Search Console.

These checks cannot guarantee search rankings, but they can help identify technical problems before those problems affect users.

Final Thoughts

Building an SEO-friendly static website doesn't require a complicated framework.

HTML provides the content structure, CSS controls the presentation, and a small collection of technical best practices helps make the website easier to navigate, maintain, and understand.

The most important lesson is to think about visitors and search engines throughout development.

Use meaningful headings, descriptive links, responsive layouts, optimized images, accurate metadata, and clear page structures.

At the same time, remember that technical SEO is only part of the picture.

Your website still needs useful, original information that answers real questions and serves a clear purpose.

A simple static website built thoughtfully can provide a strong foundation for both users and search engines.

And in many cases, starting with clean HTML and CSS is one of the best ways to understand how the web works.

Top comments (0)