Sub topic 15
Validate and publish your site
This chapter assumes you have a finished index.html and styles.css from the earlier chapters. It also assumes you can use a terminal for a few basic commands. You will check the page for errors, then put it on a static host. A static host is a service that serves your files as they are, with no server-side code.
Validate the HTML and CSS
Browsers forgive many mistakes, so a page can look right and still contain errors. Those errors can break in other browsers or confuse screen readers. A validator reads your code and lists them.
- HTML: paste your code into the W3C Nu Html Checker at validator.w3.org/nu, or upload the file.
- CSS: use the W3C CSS Validator at jigsaw.w3.org/css-validator.
These are the errors you are most likely to see in this project:
| Message or symptom | Cause | Fix |
|---|---|---|
| Duplicate ID | Two elements share one `id`, so an anchor link may jump to the wrong one | Make every `id` unique |
| Element `img` is missing `alt` | The image has no text alternative | Add descriptive `alt` text, or `alt=""` for decorative images |
| Stray end tag | A closing tag has no matching opening tag | Match each tag pair |
| Missing `lang` | The `<html>` tag has no language | Use `<html lang="en">` |
| Property is unknown | A typo in a CSS property name | Correct the spelling |
Fix errors from the top of the list first. One unclosed tag can cause several messages further down.
Run a final quality check
Validators check syntax. They do not check whether the page works for people, so test these things too:
- Click every nav link and confirm it scrolls to the right section.
- Press Tab through the page. Each link should show a visible focus outline.
- Narrow the browser window to phone width. Nothing should scroll sideways.
- Open Lighthouse in Chrome DevTools and run the Accessibility audit. Fix any contrast or missing-label warnings.
Prepare the files for publishing
Hosts serve a file named index.html at the site's root address, so keep that exact name. Use this layout:
my-site/
├── index.html
├── styles.css
└── images/
├── photo-400.jpg
└── photo-800.jpgTwo mistakes cause most broken sites after upload:
- Your computer may ignore letter case in file names, but most hosts do not.
Photo-800.JPGandphoto-800.jpgare different files there, so match the case in yoursrcandhrefvalues exactly. - Use relative paths such as
images/photo-800.jpg. A path likeC:\Users\jane\photo.jpgonly works on your own machine.
Publish to a static host
Netlify, Cloudflare Pages and GitHub Pages all work for a one-page site, and all have free plans. This example uses GitHub Pages. It assumes you have a GitHub account and an empty repository named my-site.
cd my-site
git init
git add .
git commit -m "Publish personal site"
git branch -M main
git remote add origin https://github.com/YOUR-USERNAME/my-site.git
git push -u origin mainReplace YOUR-USERNAME with your account name. In the repository, open Settings, then Pages. Set the source to the main branch and the root folder, then save. After a minute or two, the page appears at https://YOUR-USERNAME.github.io/my-site/.
Check the live site
Open the live address on your phone, not only your computer. Reload with a hard refresh if you see old content, because browsers cache files. If the page loads without styles, the stylesheet path is almost always wrong. Compare the href in your <link> tag with the real file name and its letter case.
Exercise
You publish your site and the page loads, but the photo is missing and the CSS is not applied. Your files are named Styles.css and Photo-800.jpg, while your HTML refers to styles.css and photo-800.jpg. Why does this work on your computer but not on the host, and what do you change?
Show answer
The host treats file names as case-sensitive, so styles.css and Styles.css are different files there, while your computer ignored the difference. Rename the files, or change the href and src values, so the letter case matches exactly. Then push the change and hard refresh.