File Names
File names should include no whitespace. Use only letters and numbers. You can replace spaces with an underscore ( _ ) or you can use camelCase toIndicate whereNewWordsStart.
Give your files descriptive names*.
For example, instead of "Untitled.jpg" or "Screenshot 2027-11-11 at 11.11.11 AM.png", use "happyCow.jpg" or "happy_cow_1.png"
"index.html"
*While you should give most files descriptive names, the landing page for your website should always be named index.html. This is important in our class because we are publishing webpages via GitHub, which automatically looks for an "index.html" file as the default landing page.
File Extensions
The three or four letters that follow the file name are called the file extension. The file extension tells the computer how to interpret the file.
-
If you want a file to be an HTML webpage, it needs to end with the
.html file extension.
-
If you want a file to be a CSS stylesheet, it needs to end with the
.css file extension.
-
If you want a file to be JavaScript code, it needs to end with the
.js file extension.
Also pay attention to the file extensions used for image files. Generally, .png, .jpg (or .jpeg), and .svg files will appear in the browser without any issues.
File Paths
In HTML, you must refer to a file by its file path relative to the location of the HTML page from which the file is referenced. A relative file path will look for files in the folder (or "directory") where it resides, so you must also save all required files (stylesheets, images, scripts, etc.) somewhere in that directory.
This video - Understanding File Paths - gives a more complete explanation of absolute and relative file paths.
Organizing Images
If you have multiple images, is best practice to create an "images" folder inside your website directory and store all images there.
Once you create an "images" folder, all of your image src attributes need to include the path through the folder and to the file. For example:
<img src="images/happy_cow_1.png">
It is best practice to include "alt-text" for images, which will display in place of the image if the image fails to load, and also provides a description of the image for vision-impaired users. For example:
<img src="images/happy_cow_1.png" alt="Photo of a cow smiling at the camera">