Organizing your project files is crucial for maintainability. A common structure looks like this:
your-website-folder/
├── index.html
├── css/
│ └── style.css
├── js/
│ └── script.js
├── img/
│ ├── logo.png
│ └── background.jpg
└── fonts/
└── your-font.woff2
Link your CSS file in the <head> section of your HTML:
<head>
<link rel="stylesheet" href="css/style.css">
</head>
Include your JavaScript file just before the closing <body> tag or in the
<head> (using async or defer for better performance):
<body>
<!-- Your page content -->
<script src="js/script.js"></script>
</body>
Using defer is generally recommended for scripts that are not critical for the
initial render.
Use the <img> tag to embed images:
<img src="img/logo.png" alt="Your Logo">
You can include fonts using CSS, often with the @font-face rule in your CSS file:
/* In css/style.css */
@font-face {
font-family: 'YourCustomFont';
src: url('../fonts/your-font.woff2') format('woff2');
/* Add other font formats for better browser compatibility */
font-weight: normal;
font-style: normal;
}
body {
font-family: 'YourCustomFont', sans-serif;
}
Set the page title within the <title> tags in the <head>:
<head>
<title>Your Website Title</title>
</head>
Add a favicon (the small icon in the browser tab) by linking it in the <head>:
<head>
<link rel="icon" href="img/favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon">
<!-- For modern browsers, you might use a PNG: -->
<link rel="icon" type="image/png" href="img/favicon.png" sizes="32x32">
</head>
<title>.<meta name="description"> tag.
<article>,
<nav>, <main>, <header>,
<footer>, etc.
<h1> for the main heading, followed by
<h2> to <h6> for subheadings.
alt attributes for your
<img> tags.
Specify the language of your HTML document using the lang attribute in the
<html> tag:
<html lang="en">
You can use language codes like "en" for English, "es" for Spanish, "fr" for French, etc. You can also specify regional variations like "en-US" or "en-GB".
Make your website responsive so it adapts to different screen sizes and devices:
<head>:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
/* Example for screens smaller than 600px wide */
@media screen and (max-width: 599px) {
body {
font-size: 14px;
}
/* Adjust layout and other styles as needed */
}
<picture> element or the
srcset and sizes attributes of the <img> tag to serve
different image sizes based on the device.
These are fundamental best practices for structuring your webpage and ensuring it's well-organized, accessible, and optimized.