A web application is a complex map of interconnected files. Knowing the HTML `<img>` tag is useless if you cannot instruct the browser on exactly how to locate the image file on your server. Mastering 'pathing'βthe technical logic of directory navigationβis what separates beginners from software architects.
1Relative Pathing & Local Context
A Relative Path forces the browser to search for a file relative to the exact location of the current HTML document. It assumes the HTML file is the 'center of the universe'.
If you place an image directly next to your HTML file, the path is simply the filename (src="logo.png"). If you organize your images into a subfolder, you must provide the folder name followed by a forward slash (src="assets/logo.png"). Relative paths are critical because they allow your entire codebase to be migrated from your local computer to a production server without breaking; the relationships between the files remain intact.
2Parent Directory Traversal
Professional codebases are deeply nested. Your HTML file might live deep inside pages/dashboard/, while your core images live globally in assets/img/. To link these, you must 'climb out' of your current folder tree.
The syntax ../ acts as an override command telling the browser to step 'up' into the parent directory. Every ../ you append climbs one level higher. So ../../assets/img/logo.png tells the engine: 'Go up two folders, then enter the assets folder, then enter the img folder, and finally grab the logo'.
3Absolute Paths & CDNs
Sometimes, the image you need does not exist anywhere on your local server. It exists on a completely separate domain, like an Amazon S3 bucket or a global Content Delivery Network (CDN) designed to load assets at lightning speeds.
To retrieve these, you use an Absolute URL. An absolute path ignores folders entirely and provides the exact, full web address of the resource, beginning with the protocol https://. If you omit the protocol, the browser assumes you are searching your local folders, resulting in a fatal 404 error.
