HTML File and Folder Naming Best Practices
Tags: html
Published: 2020-12-15 04:14:28

<h1>HTML and CSS File and Folder Naming Best Practices</h1>
<p>Unlike regular files, in HTML and CSS file naming is important, and there are quite a few rules that you should follow to make sure your files are displayed and can be linked.</p>
<ul>
<li><p>Rule 1: <strong>No spaces on folders or file names</strong>
Spaces in file names will create broken links to files and/or folders (including images)</p></li>
<li><p>Rule 2: <strong>Only use alphanumeric characters</strong> (letters and numbers)
Note: You can also use the hyphen and underscore, but it is better to avoid them when possible
Some characters are reserved for use by the operating system or by other programs.
Some examples are: "\, /, :, *, ?, ", &lt;, &gt;, and. | " </p></li>
<li><p>Rule 3: <strong>Don't start your file name with numbers</strong>
Because some programs give special treatment to files that start with a number, it is a good practice to avoid using numbers to start a file or folder name.</p></li>
<li><p>Rule 4: <strong>Use all lowercase</strong>
Saves you the effort of remembering when you used uppercase letters</p></li>
<li><p>Rule 5: <strong>Keep folder and file names short and meaningful</strong>.</p></li>
<li><p>Rule 6: <strong>Be consistent with your extension</strong>. Always use .htm or .html for all your files.
Aside from .htm being a short extension, there is no difference between using one extension over the other, but you must remain consistent. Once you decide which extension you rather use, stick with that one for all of your files.</p></li>
<li><p>One rule to rule them all: <strong>The easiest way to name your files is simply by using letters and numbers (but not at the beginning of the file)</p></li>
</ul>
<p>Here are some examples of good application of these rules:
As you look at the example, try to use the rules to identify:</p>
<ul>
<li><p>why the example is bad, </p></li>
<li><p>what makes it better, and </p></li>
<li><p>what makes it best</p></li>
</ul>
<table>
<thead>
<tr>
<th>Bad Example</th>
<th>Better</th>
<th>Best</th>
</tr>
</thead>
<tbody>
<tr>
<td><span title="Contains a space">Contact us.html</span></td>
<td>Contact_us.html</td>
<td>contactus.html</td>
</tr>
<tr>
<td><span title="Starts with a number">2Page.html</span></td>
<td>Page2.html</td>
<td>page2.html</td>
</tr>
<tr>
<td><span title="Contains reserved characters">MyDog&amp;I.html</span></td>
<td>myDog_and_I.html</td>
<td>mydog.html</td>
</tr>
<tr>
<td><span title="Contains a space">My background.jpg</span></td>
<td>MyBackground.jpg</td>
<td>background.jpg</td>
</tr>
<tr>
<td><span title="Starts with a number">2Background.png</span></td>
<td>Background_2.png</td>
<td>background2.png</td>
</tr>
</tbody>
</table>
<h2>Your index file</h2>
<p>Lastly, remember that the main page (or landing page) of each folder on any HTML project should always be named <strong>index.htm</strong> or <strong>index.html</strong>.
This is important because the server will always look for the index page to be displayed, unless the web administrator indicates something different.</p>
<p>Note: Once you gain more experience as a web developer, you may encounter other extensions used when creating web pages with different technologies (.asp, .cfm, .asp, php, and .shtml).
</p><hr>