Sub topic 15
Validate and publish your site
You now have a finished page. This chapter covers the last two steps: checking that the page is valid and accessible, then putting it on a public web address. Checking comes first because it is cheaper to fix a problem on your own machine than on a live site.
This chapter assumes you have a working index.html and styles.css. It also assumes you have used the viewport meta tag, media queries, anchor links, alt text and visible focus styles from earlier chapters. For the publishing step you need a free account on a static host, and Git installed if you choose GitHub Pages.
Why validate before you publish
Browsers forgive a lot. They guess what you meant when a tag is missing or misnested, and different browsers can guess differently. A page that looks fine in your browser can break in another browser, or for a screen reader that relies on correct structure.
Validation is an automated check against the HTML and CSS rules. It catches typing mistakes and structural errors early. It does not judge design or content, and it does not prove the page is accessible. You need both a validator and a manual review.
Validate the HTML
Use the W3C Nu HTML Checker at validator.w3.org/nu. It has three input modes: enter a public URL, upload a file, or paste the source. Paste or upload works before you publish. The checker reports each problem as an error or a warning, with a line number.
Errors are real rule violations, so fix all of them. Warnings are advice, so read each one and decide.
The table lists errors you are likely to meet on a page like yours.
| Message (shortened) | Cause | Fix |
|---|---|---|
| Duplicate ID `projects` | Two elements share one `id` | Give each `id` a unique value. A duplicate also breaks anchor links, because the browser scrolls to the first match. |
| An `img` element must have an `alt` attribute | Missing alt text | Add a description, or `alt=""` for a purely decorative image. |
| Stray end tag `h3` | Opening and closing tags do not match | Make the closing tag match the opening one. |
| Element `li` not allowed as child of `div` | List items outside a `ul` or `ol` | Wrap the items in a list. |
| Section lacks heading | A `section` has no `h1` to `h6` | Add a heading, or use a `div` if it is not a real section. |
| Missing `lang` attribute | `<html>` has no language | Use `<html lang="en">`. |
Here is a typical broken fragment and its corrected version.
<!-- Broken: three problems -->
<section id="projects">
<h2>Projects</h3>
<img src="photo-800.jpg">
<p>See my work <a href="https://example.com">here
</section><!-- Fixed -->
<section id="projects">
<h2>Projects</h2>
<img src="photo-800.jpg" width="800" height="800"
alt="Portrait of Jane Doe at her desk">
<p>See my work <a href="https://example.com">on my portfolio site</a>.</p>
</section>The fix also changes the link text from "here" to a phrase that makes sense out of context. Screen reader users often list all links on a page, and a list of "here" entries is useless.
Re-run the checker after each round of fixes. One early mistake, such as an unclosed tag, can cause a chain of later errors that disappear when you fix it. Start at the first error in the list.
Validate the CSS
The W3C CSS Validator at jigsaw.w3.org/css-validator accepts a URL, an upload or pasted text. It flags unknown properties, bad values and unbalanced braces.
Be careful with its output. A newer feature, such as :focus-visible or padding-inline, may be reported as an error if the validator's rule set is older than the browser support. A custom property used through var() can also be reported as a warning. Check any such message against current browser documentation before you change working code.
In your own browser, open DevTools and look at the Console and the Elements panel. A rule that is struck through in the Styles pane was overridden by a more specific one. That is a cascade problem, not a validity problem, and the validator will not report it.
Audit accessibility and responsiveness
Run an automated audit first, then check by hand. Automated tools find roughly the mechanical problems, such as low contrast and missing alt text. They cannot tell whether your alt text is meaningful.
Automated checks
- Lighthouse is built into Chrome DevTools. Run it with the Accessibility category selected, and read the failed items.
- WAVE (browser extension) marks landmarks, headings and contrast failures on the page itself.
- axe DevTools (browser extension) lists issues with the element that caused each one.
Aim to fix every failed item. A score of 100 does not mean the page is accessible. It means the automated rules found nothing.
Manual checks
- Press Tab repeatedly from the top of the page. Every link should receive a visible outline, in a sensible order. Nothing should trap focus.
- Click each navigation link. Each should scroll to the right section, and the heading should not hide under other content (this is what
scroll-margin-topis for). - Zoom the browser to 200%. Text should reflow without horizontal scrolling or overlapping content.
- Resize the window down to about 320 px wide, or use DevTools device mode. The grid should collapse to one column and the navigation should stay usable.
- Read the heading outline. There should be one
h1, and no level should be skipped, such ash2straight toh4. - Turn on the operating system's reduced-motion setting and confirm smooth scrolling is off.
Prepare the files for hosting
A static host serves your files exactly as they are. It runs no server code, which is why it is free or cheap and hard to break. Three conventions matter.
- The home page must be named
index.html. Hosts serve it when someone visits the bare address. - Use relative paths such as
styles.cssandimages/photo-800.jpg. A root-relative path like/styles.cssbreaks when the site lives in a subfolder of the host's address, as GitHub project pages do. - Match file name case exactly. Your laptop may treat
Photo-800.jpgandphoto-800.jpgas the same file, but most hosts run Linux and treat them as different files. A mismatch gives you a broken image only after publishing.
A tidy project folder looks like this:
jane-site/
├── index.html
├── styles.css
└── images/
├── photo-400.jpg
└── photo-800.jpgIf you reference an image in srcset, make sure every listed file is in the folder. A missing candidate fails only on screens that choose it, so you may not notice it locally.
Publish the site
Three free static hosts suit a one-page site.
| Host | How you publish | Address you get |
|---|---|---|
| GitHub Pages | Push to a repository and enable Pages | `username.github.io` |
| Netlify | Drag the folder onto Netlify Drop, or connect a repository | A generated `*.netlify.app` name |
| Cloudflare Pages | Connect a repository or upload files | A `*.pages.dev` name |
All three can later use your own domain name. The steps below use GitHub Pages because the result is version-controlled, so you can undo a bad change.
- Create an empty repository named
USERNAME.github.ioon GitHub, replacingUSERNAMEwith your account name. - Run these commands inside your project folder.
git init -b main
git add index.html styles.css images/
git commit -m "Publish personal site"
git remote add origin https://github.com/USERNAME/USERNAME.github.io.git
git push -u origin main- In the repository, open Settings, then Pages. Under Build and deployment, choose "Deploy from a branch", select
mainand the/ (root)folder, and save. - Wait a minute or two, then open
https://USERNAME.github.io/.
To update the site later, edit the files, then run git add, git commit and git push again. The host rebuilds automatically.
Verify the live site
Do not assume the published site matches your local copy. Open the public address in a private window so no cached files interfere, then check:
- The page loads with its styles. Unstyled text usually means the stylesheet path is wrong or has a case mismatch.
- Every image appears.
- Each in-page link scrolls to its section, and the address bar shows
#about,#projectsand so on. - The page works on a real phone, not only in DevTools device mode.
- The title in the browser tab is correct.
Then run the Nu checker once more using the live URL. It now fetches exactly what visitors receive.
Summary of the release routine
- Validate the HTML and fix every error.
- Validate the CSS and check any doubtful message by hand.
- Run Lighthouse, then do the keyboard, zoom and narrow-screen checks.
- Confirm
index.html, relative paths and file name case. - Publish, then test the live address in a private window.
Exercise
After you publish, the page shows plain unstyled text, but it looked correct on your laptop. The file is named Styles.css and the link tag says href="styles.css". Explain the likely cause and give two fixes.
Show answer
The host runs a case-sensitive file system, so styles.css does not match Styles.css, and the stylesheet returns "not found". Your laptop ignored the difference in case. Fix 1: rename the file to styles.css (in Git, use git mv Styles.css styles.css, and on case-insensitive systems you may need a temporary name first). Fix 2: change the href to Styles.css. Lowercase names are better, because they avoid the problem in future.
Exercise
The Nu checker reports "Duplicate ID contact". Why is this more than a cosmetic problem on your page, and how do you fix it?
Show answer
Two elements with the same id make the anchor link #contact ambiguous. The browser scrolls to the first match, so the link may go to the wrong place, and scripts or CSS selectors that use the id can also hit the wrong element. Give each element a unique id, then update any link that should point to the second one.