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:
- Check the name. All lowercase, no spaces, nothing but letters, numbers and
-— and the right extension. - Absolute or relative? Does the address start with
https://— another site — or is it a path inside your own? - 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.
- Can a browser show the file? And is it the right format, at the right size, for its job?
Naming files
Six rules
| Rule | Right | Wrong |
|---|---|---|
| all lowercase | about.html | About.html |
no spaces — use - | beach-day.webp | beach day.webp |
only a–z, 0–9 and - | team-2026.webp | team#1.webp · photo(2).jpg · 照片.jpg · café.jpg |
| the extension in lowercase, too | photo.jpg | photo.JPG |
| short, and says what is in it | campus-lake.webp | IMG_20260914_083112.jpg · final-FINAL-2.html |
index.html for the front page | index.html | home.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 name | In the address |
|---|---|
my photo.webp | my%20photo.webp |
照片.webp | %E7%85%A7%E7%89%87.webp |
café.webp | caf%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
| Part | Here | Its job |
|---|---|---|
| scheme | https:// | how to talk to the server — https is encrypted |
| host | shop.example.com | which machine; DNS turns the name into a number |
| port | :443 | which door on the machine — almost always left out |
| path | /menu/drinks.html | which file on that machine |
| query | ?lang=en | extra information, sent along with the request |
| fragment | #tea | a 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
| Kind | Looks like | Starts from | Use it for |
|---|---|---|---|
| absolute | https://developer.mozilla.org/en-US/ | nowhere — it is complete | other sites · and og:image, which needs the full address |
| relative | about.html · images/hero.webp · ../index.html | the folder of the current page | your own pages and files |
| root-relative | /images/hero.webp | the top of the host | avoid 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 in | To reach | The path |
|---|---|---|
index.html | style.css | style.css |
index.html | hero.webp | images/hero.webp |
index.html | favicon-32.png | images/icons/favicon-32.png |
projects/machine.html | index.html | ../index.html |
projects/machine.html | style.css | ../style.css |
projects/machine.html | hero.webp | ../images/hero.webp |
| You write | It means |
|---|---|
about.html or ./about.html | in the same folder as this page |
images/ | down, into the folder images |
../ | up one folder |
../../ | up two folders |
/ between two names | it 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.
| Address | Verdict | Why |
|---|---|---|
https://example.com/about.html | ✓ valid | scheme, host and path — complete |
https://example.com/ | ✓ valid | only a folder: the server sends its index.html |
contact.html#form | ✓ valid | a page in the same folder, and a place on it |
mailto:mei@example.com | ✓ valid | opens a mail program |
http://example.com | ✓ valid, but | not encrypted — the browser says Not secure. Use https:// |
example.com/about.html | ✗ broken | no https://, so it is read as a relative path: a folder called example.com inside your site |
https//example.com | ✗ broken | the : is missing — again a relative path |
images/Logo.PNG for the file logo.png | ✗ broken | the capitals: fine on your laptop, a 404 on the server |
file:///C:/Users/mei/Desktop/site/index.html | ✗ broken | a file on your own disk. Nobody else has your C: drive |
images\logo.png | ✗ invalid | a backslash. Addresses use / |
my page.html | ✗ invalid | a space. Rename the file my-page.html |
File types the web can use
Made for the web
| For | Format | Where it goes |
|---|---|---|
| pages | .html | linked 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 | .json | fetch('quotes.json') |
| a document to download or print | .pdf | a link, <a href="cv.pdf"> — the browser opens it in its own viewer |
Works, but there is a better choice
| Format | The problem | Use instead |
|---|---|---|
.gif | ten times the size of an MP4, at worse quality, and only 256 colours | .mp4 for animation · .png or .svg for a small graphic |
.bmp | no compression at all: huge | .png |
.ico | the old Windows icon format | .png for the favicon |
.ttf · .otf | desktop fonts — much larger than they need to be | .woff2 |
.mov | plays in some browsers, not in others | .mp4 |
A browser cannot show these — convert first
| File | What it is | Convert to |
|---|---|---|
.heic | an iPhone photo — only Safari shows it | .webp or .jpg |
.psd | a Photoshop file | export .webp, .png or .jpg |
.ai · .fig · .sketch | a design file — Illustrator, Figma, Sketch | export .svg or .png |
.tiff | a print or scanner file — only Safari shows it | .webp or .jpg |
.cr2 · .nef · .dng | a camera's raw file | .webp or .jpg |
.docx · .pages · .pptx | an office document | the text into your HTML — or a .pdf to download |
Which image format, when
Four questions, in this order
- Does it move? →
.mp4in a<video>. Not a GIF. - Is it drawn, not photographed — a logo, an icon, a diagram? →
.svg, if you have it as a drawing. Otherwise.png. - Does it need a see-through background? →
.pngor.webp. Never.jpg: it has no transparency. - Is it a photograph? →
.webp, or.jpg. A screenshot full of text →.png, which keeps the letters sharp.
The formats side by side
| Format | Compression | Transparency | Animation | Best for | Avoid for |
|---|---|---|---|---|---|
JPEG .jpg | lossy | no | no | photos | logos, text, anything see-through |
PNG .png | lossless | yes | no | screenshots, icons, cut-outs | photos — far too big |
WebP .webp | lossy or lossless | yes | yes | photos and graphics, smaller than both | — |
AVIF .avif | lossy or lossless | yes | yes | photos, smallest of all | when you need it fast — slow to export |
SVG .svg | none: it is text | yes | with CSS | logos, icons, diagrams | photos |
GIF .gif | lossless, 256 colours | on or off | yes | nothing new | animation — 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 phone | 4.0 MB |
| as JPEG, quality 80 | 850 KB |
| as WebP | 480 KB |
| as AVIF | 320 KB |
| resized to the width it is shown at | 85 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
| Image | File | Size | Format |
|---|---|---|---|
| favicon | favicon-32.png | 32 × 32 | PNG |
| app icon | apple-touch-icon.png | 180 × 180 | PNG, square corners |
| Open Graph image | og-image.jpg | 1200 × 630, under 100 KB | JPG 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 capitalIMG_4521.JPG→ a name that says what it is, in lowercase:campus-lake.jpgquotes(2).html→quotes-2.html— brackets我的照片.jpg→my-photo.jpg— characters outsidea–zstyle.CSS→style.css— the extension in capitalscontact 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
- In
index.html, the path tologo.svg - In
recipes/noodles.html, the path tostyle.css - In
recipes/noodles.html, the path tohero.webp - In
index.html, a link tonoodles.html - In
recipes/noodles.html, a link to the recipes front page - The site is live at
https://mei.github.io/my-site/. What is the shortest address of the recipes front page? recipes/noodles.htmlhas<link rel="stylesheet" href="style.css">. The page shows no styles at all. Why?
Show the answers
images/logo.svg../style.css../images/hero.webprecipes/noodles.htmlindex.html— the recipes front page is in the same folderhttps://mei.github.io/my-site/recipes/— a folder address: the server sends itsindex.html- 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
- ✓ valid — an absolute address, for another site
- ✗ broken — no
https://, so it looks for a folder calledwww.w3.orginside your site - ✗ invalid — a backslash. Use
/ - ✓ valid — a page in the folder
recipes, and a place on it - ✗ broken — root-relative: it looks for
https://mei.github.io/images/hero.webp, outsidemy-site - ✗ invalid — a space. Rename the file
summer-holiday.webp
4 · Choose the format
- The photo of the beach at the top of your homepage
- Your logo, drawn in Figma
- A screenshot of your code, for a page that explains it
- A four-second animation of your useless machine
- A photo of yourself with the background removed
IMG_2041.HEIC, straight from your iPhone- The picture that appears when your link is shared in a chat app
- A font you downloaded as
.ttf
Show the answers
- WebP (or JPEG), resized to about 1600 pixels wide
- SVG — export it from Figma as SVG; it stays sharp at every size
- PNG — it keeps the letters sharp. JPEG blurs them
- MP4, in a
<video>— not a GIF, which is ten times the size - PNG or WebP — both keep the see-through background. JPEG cannot
- 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 - The Open Graph image: 1200 × 630, JPG or PNG, under 100 KB — with its absolute address in the
og:imagetag - Convert it to WOFF2 — the format made for the web, and much smaller