File Paths and Favicon in HTML: A Comprehensive Guide
Sharique Siddiqui

Sharique Siddiqui @sharique_siddiqui_8242dad

About: Full Stack Java Developer with 5+ years of experience in Spring Boot, React, REST APIs, and MySQL. Passionate about clean code and building scalable web apps.

Joined:
Jul 28, 2025

File Paths and Favicon in HTML: A Comprehensive Guide

Publish Date: Aug 14
2 2

Understanding file paths and favicons is essential for web developers to organize website resources effectively and create a polished user experience. This blog post explains what file paths are, how to use them in HTML, and how to add a favicon to your website for brand recognition in browser tabs.

File Paths in HTML

A file path in HTML describes the location of a file within a website's folder structure. It's used to link external resources such as images, stylesheets, scripts, and other web pages.

Types of File Paths

There are two main types of file paths:

1. Absolute File Paths

These include the full URL (web address) starting with the protocol (http:// or https://), domain, and the exact location of the file.

Best for linking to external resources hosted on other servers.

Example:
xml
<img src="https://www.example.com/images/photo.jpg" alt="Example Photo">
Enter fullscreen mode Exit fullscreen mode
2. Relative File Paths

These specify the location of a file relative to the current HTML document.

Preferred for linking resources within the same website because they make the site more portable between environments (local, staging, production).

Use dot notation to navigate directories:

  • ./ refers to the current directory.
  • ../ moves one level up in the folder hierarchy.

Common Usage:

Path Example Meaning
image.jpg File is in the same folder as the HTML file
images/image.jpg File is in an images subfolder inside current folder
/images/image.jpg File is in the images folder at the root of the website
../image.jpg File is in the parent folder of the current folder
Example:
xml
<img src="images/photo.jpg" alt="Photo in images folder">
Enter fullscreen mode Exit fullscreen mode

Best Practice

Use relative file paths when possible to keep your project flexible and easier to maintain across different hosting environments.

What Is a Favicon?

A favicon (short for "favorite icon") is a small icon that represents your website. It appears in places like:

  • Browser tabs (next to the page title)
  • Bookmarks/favorites list
  • Browser history
  • Mobile search results
  • Favicons enhance user experience and brand recognition by giving a visual identity to your site.
How to Add a Favicon to Your Website
Step 1: Create or Obtain a Favicon Image
  • Favicons are usually small (commonly 16x16 or 32x32 pixels).
  • Ideal formats: .ico, .png, .gif, .jpg, or .svg.
  • Keep the design simple and high contrast for visibility at small sizes.
  • You can create favicons using online tools like favicon.
Step 2: Save the Favicon Image
  • Save your favicon file to your website folder, typically in the root directory or an images folder.
  • A common filename is favicon.ico, but other formats and names can be used as long as you link them properly.
Step 3: Link the Favicon in Your HTML Document

Add the following <link> element inside the

section of your HTML file, after the <title> tag:
xml
<link rel="icon" type="image/x-icon" href="favicon.ico">
Enter fullscreen mode Exit fullscreen mode

If your favicon is in a subfolder (e.g., images), update the path accordingly:

xml
<link rel="icon" type="image/png" href="images/favicon.png">
Enter fullscreen mode Exit fullscreen mode
Complete Example:
xml
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>My Website</title>
  <link rel="icon" type="image/x-icon" href="favicon.ico" />
</head>
<body>
  <h1>Welcome to My Website</h1>
  <p>This site has a favicon.</p>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode
Step 4: Test Your Favicon
  • Load your website in different browsers.
  • Clear your browser cache or hard refresh (Ctrl + F5) if the favicon doesn’t show up immediately.
Supported Favicon Formats
Format Browser Support
.ico Universal support
.png All major browsers
.gif All major browsers
.jpg All major browsers
.svg Supported in modern browsers

Final Thoughts

File paths tell browsers where to find files your webpage needs. Use relative paths to keep your website portable.

  • A favicon is a tiny icon that represents your site in browser tabs and bookmarks.
  • To add a favicon, put the icon file in your project folder and link it in the <head> section with a <link rel="icon"> tag.
  • Use simple, high-contrast images sized for small icons to ensure best visibility.

Understanding and correctly using file paths alongside adding a favicon are essential components of professional web development to organize your site’s assets and enhance user experience through visual branding.

Check out the YouTube Playlist for great HTML content for basic to advanced topics.

Please Do Subscribe Our YouTube Channel for clearing programming concept and much more ...CodenCloud

Comments 2 total

  • Anik Sikder
    Anik SikderAug 15, 2025

    This guide is super clear and beginner-friendly. It explains file paths and favicons in a way that’s easy to follow, with practical examples and best practices. Loved how it breaks down relative vs absolute paths and even includes browser support for favicon formats. Great resource for anyone building their first site or polishing up their HTML skills.

Add comment