Files, URLs and Formats

Name a file so it works on every server, read any path or address, and choose the right format for every image, video and font.

A method for any file or address

Every time, in this order:

  1. Check the name. All lowercase, no spaces, nothing but letters, numbers and - — and the right extension.
  2. Absolute or relative? Does the address start with https:// — another site — or is it a path inside your own?
  3. Find where the path starts. A relative path starts in the folder of the page it is written in. Not in the site's main folder, and not on your Desktop.
  4. Can a browser show the file? And is it the right format, at the right size, for its job?

Naming files

Six rules

RuleRightWrong
all lowercaseabout.htmlAbout.html
no spaces — use -beach-day.webpbeach day.webp
only a–z, 0–9 and -team-2026.webpteam#1.webp · photo(2).jpg · 照片.jpg · café.jpg
the extension in lowercase, toophoto.jpgphoto.JPG
short, and says what is in itcampus-lake.webpIMG_20260914_083112.jpg · final-FINAL-2.html
index.html for the front pageindex.htmlhome.html · Index.html

Folders follow the same rules: images, not Images or My Images.

Why each rule exists

Capitals. Windows and macOS treat About.html and about.html as the same file. The Linux servers behind GitHub Pages and almost every host treat them as two different files. A link to About.html works on your laptop and is a 404 online — the most common "it works on my machine" failure in this course.

Spaces and special characters. An address cannot contain them, so the browser rewrites them:

File nameIn the address
my photo.webpmy%20photo.webp
照片.webp%E7%85%A7%E7%89%87.webp
café.webpcaf%C3%A9.webp

Some characters already have a job in an address, so in a file name they break it. # starts the fragment: a link to team#1.webp asks the server for a file called team. ? starts the query. % starts an encoded character.

-, not _. Search engines read a hyphen as a space between words: campus-lake is two words, campus_lake is one. Pick - and use it everywhere.

index.html. When an address names only a folder, the server sends that folder's index.html. That is why https://mei.github.io/my-site/ opens my-site/index.html — and why a front page called home.html is never found on its own.


Addresses and paths

The parts of an address

https://shop.example.com:443/menu/drinks.html?lang=en#tea
PartHereIts job
schemehttps://how to talk to the server — https is encrypted
hostshop.example.comwhich machine; DNS turns the name into a number
port:443which door on the machine — almost always left out
path/menu/drinks.htmlwhich file on that machine
query?lang=enextra information, sent along with the request
fragment#teaa place on the page, the element with id="tea" — never sent to the server

Capitals: the scheme and the host do not care — HTTPS://EXAMPLE.COM is https://example.com. The path does: /About.html and /about.html are two different files.

Three kinds of address

KindLooks likeStarts fromUse it for
absolutehttps://developer.mozilla.org/en-US/nowhere — it is completeother sites · and og:image, which needs the full address
relativeabout.html · images/hero.webp · ../index.htmlthe folder of the current pageyour own pages and files
root-relative/images/hero.webpthe top of the hostavoid it on GitHub Pages

Why avoid the third one? Your site lives at https://mei.github.io/my-site/, but the top of the host is https://mei.github.io/. So /images/hero.webp looks for https://mei.github.io/images/hero.webp — outside your site, a 404. A relative path, images/hero.webp, works on your laptop and on every server.

Reading a relative path

my-site/
├── index.html
├── style.css
├── images/
│   ├── hero.webp
│   └── icons/
│       └── favicon-32.png
└── projects/
    └── machine.html
Written inTo reachThe path
index.htmlstyle.cssstyle.css
index.htmlhero.webpimages/hero.webp
index.htmlfavicon-32.pngimages/icons/favicon-32.png
projects/machine.htmlindex.html../index.html
projects/machine.htmlstyle.css../style.css
projects/machine.htmlhero.webp../images/hero.webp
You writeIt means
about.html or ./about.htmlin the same folder as this page
images/down, into the folder images
../up one folder
../../up two folders
/ between two namesit separates folders — always forward, never \

Valid, broken or invalid?

An address can fail in two different ways. Invalid: it breaks the rules for addresses, and the validator reports it. A browser sometimes repairs it quietly — never rely on that. Broken: it follows the rules, but it points to the wrong place, so nothing arrives.

AddressVerdictWhy
https://example.com/about.html✓ validscheme, host and path — complete
https://example.com/✓ validonly a folder: the server sends its index.html
contact.html#form✓ valida page in the same folder, and a place on it
mailto:mei@example.com✓ validopens a mail program
http://example.com✓ valid, butnot encrypted — the browser says Not secure. Use https://
example.com/about.html✗ brokenno https://, so it is read as a relative path: a folder called example.com inside your site
https//example.com✗ brokenthe : is missing — again a relative path
images/Logo.PNG for the file logo.png✗ brokenthe capitals: fine on your laptop, a 404 on the server
file:///C:/Users/mei/Desktop/site/index.html✗ brokena file on your own disk. Nobody else has your C: drive
images\logo.png✗ invalida backslash. Addresses use /
my page.html✗ invalida space. Rename the file my-page.html

File types the web can use

Made for the web

ForFormatWhere it goes
pages.htmllinked with <a href="about.html">
the look.css<link rel="stylesheet" href="style.css"> in the head
behaviour.js<script src="nav.js"></script>
photographs.webp · .jpg · .avif<img src="…" alt="…">
graphics with transparency, screenshots.png · .webp<img src="…" alt="…">
logos, icons, diagrams.svg<img src="logo.svg" alt="…">, or the <svg> code itself in the page
video and animation.mp4<video src="machine.mp4" controls></video>
sound.mp3<audio src="intro.mp3" controls></audio>
fonts.woff2@font-face in the CSS
the tab icon.png, 32 × 32<link rel="icon" href="favicon-32.png">
the home-screen icon.png, 180 × 180<link rel="apple-touch-icon" href="apple-touch-icon.png">
data for JavaScript.jsonfetch('quotes.json')
a document to download or print.pdfa link, <a href="cv.pdf"> — the browser opens it in its own viewer

Works, but there is a better choice

FormatThe problemUse instead
.giften times the size of an MP4, at worse quality, and only 256 colours.mp4 for animation · .png or .svg for a small graphic
.bmpno compression at all: huge.png
.icothe old Windows icon format.png for the favicon
.ttf · .otfdesktop fonts — much larger than they need to be.woff2
.movplays in some browsers, not in others.mp4

A browser cannot show these — convert first

FileWhat it isConvert to
.heican iPhone photo — only Safari shows it.webp or .jpg
.psda Photoshop fileexport .webp, .png or .jpg
.ai · .fig · .sketcha design file — Illustrator, Figma, Sketchexport .svg or .png
.tiffa print or scanner file — only Safari shows it.webp or .jpg
.cr2 · .nef · .dnga camera's raw file.webp or .jpg
.docx · .pages · .pptxan office documentthe text into your HTML — or a .pdf to download

Which image format, when

Four questions, in this order

  1. Does it move? → .mp4 in a <video>. Not a GIF.
  2. Is it drawn, not photographed — a logo, an icon, a diagram? → .svg, if you have it as a drawing. Otherwise .png.
  3. Does it need a see-through background? → .png or .webp. Never .jpg: it has no transparency.
  4. Is it a photograph? → .webp, or .jpg. A screenshot full of text → .png, which keeps the letters sharp.

The formats side by side

FormatCompressionTransparencyAnimationBest forAvoid for
JPEG .jpglossynonophotoslogos, text, anything see-through
PNG .pnglosslessyesnoscreenshots, icons, cut-outsphotos — far too big
WebP .webplossy or losslessyesyesphotos and graphics, smaller than both—
AVIF .aviflossy or losslessyesyesphotos, smallest of allwhen you need it fast — slow to export
SVG .svgnone: it is textyeswith CSSlogos, icons, diagramsphotos
GIF .giflossless, 256 colourson or offyesnothing newanimation — use MP4

Lossy throws away detail you barely see, to make the file much smaller. Lossless keeps every pixel exactly. An SVG is not pixels at all, but instructions for drawing — so it stays sharp at any size, and CSS can change its colours.

WebP and AVIF work in every current browser. WebP is the safe default for anything that is not a drawing.

The size matters more than the format

The same phone photo, in What the Web Is:

Size
the original from the phone4.0 MB
as JPEG, quality 80850 KB
as WebP480 KB
as AVIF320 KB
resized to the width it is shown at85 KB

Resize first. A hero photo needs about 1600 pixels of width, not the 4000 your phone takes. Never upload a camera original.

The images your project needs

ImageFileSizeFormat
faviconfavicon-32.png32 × 32PNG
app iconapple-touch-icon.png180 × 180PNG, square corners
Open Graph imageog-image.jpg1200 × 630, under 100 KBJPG or PNG

The Open Graph image needs the absolute address: <meta property="og:image" content="https://mei.github.io/my-site/images/og-image.jpg">. The chat app that reads it is not on your site, so a relative path means nothing to it.


Practice

1 · Safe names

Which of these are safe? Rename the others.

about-us.html     Recipes.html     hero.webp     IMG_4521.JPG
quotes(2).html    我的照片.jpg      style.CSS     contact form.html
Show the answers

Safe: about-us.html and hero.webp.

  • Recipes.html → recipes.html — a capital
  • IMG_4521.JPG → a name that says what it is, in lowercase: campus-lake.jpg
  • quotes(2).html → quotes-2.html — brackets
  • 我的照片.jpg → my-photo.jpg — characters outside a–z
  • style.CSS → style.css — the extension in capitals
  • contact form.html → contact-form.html — a space

2 · Write the path

my-site/
├── index.html
├── style.css
├── images/
│   ├── hero.webp
│   └── logo.svg
└── recipes/
    ├── index.html
    └── noodles.html
  1. In index.html, the path to logo.svg
  2. In recipes/noodles.html, the path to style.css
  3. In recipes/noodles.html, the path to hero.webp
  4. In index.html, a link to noodles.html
  5. In recipes/noodles.html, a link to the recipes front page
  6. The site is live at https://mei.github.io/my-site/. What is the shortest address of the recipes front page?
  7. recipes/noodles.html has <link rel="stylesheet" href="style.css">. The page shows no styles at all. Why?
Show the answers
  1. images/logo.svg
  2. ../style.css
  3. ../images/hero.webp
  4. recipes/noodles.html
  5. index.html — the recipes front page is in the same folder
  6. https://mei.github.io/my-site/recipes/ — a folder address: the server sends its index.html
  7. A relative path starts in the folder of the page, so it asks for recipes/style.css, which does not exist. Fix: ../style.css.

3 · Valid, broken or invalid?

Each address is written in a page of a site that is live at https://mei.github.io/my-site/.

1   https://www.w3.org/
2   www.w3.org
3   images\hero.webp
4   recipes/noodles.html#steps
5   /images/hero.webp
6   images/summer holiday.webp
Show the answers
  1. ✓ valid — an absolute address, for another site
  2. ✗ broken — no https://, so it looks for a folder called www.w3.org inside your site
  3. ✗ invalid — a backslash. Use /
  4. ✓ valid — a page in the folder recipes, and a place on it
  5. ✗ broken — root-relative: it looks for https://mei.github.io/images/hero.webp, outside my-site
  6. ✗ invalid — a space. Rename the file summer-holiday.webp

4 · Choose the format

  1. The photo of the beach at the top of your homepage
  2. Your logo, drawn in Figma
  3. A screenshot of your code, for a page that explains it
  4. A four-second animation of your useless machine
  5. A photo of yourself with the background removed
  6. IMG_2041.HEIC, straight from your iPhone
  7. The picture that appears when your link is shared in a chat app
  8. A font you downloaded as .ttf
Show the answers
  1. WebP (or JPEG), resized to about 1600 pixels wide
  2. SVG — export it from Figma as SVG; it stays sharp at every size
  3. PNG — it keeps the letters sharp. JPEG blurs them
  4. MP4, in a <video> — not a GIF, which is ten times the size
  5. PNG or WebP — both keep the see-through background. JPEG cannot
  6. Convert it to WebP or JPEG — only Safari can show HEIC — then resize it and give it a real name, like mei-at-the-beach.webp
  7. The Open Graph image: 1200 × 630, JPG or PNG, under 100 KB — with its absolute address in the og:image tag
  8. Convert it to WOFF2 — the format made for the web, and much smaller