Course contentsShow
← Web Development
Lesson 1224 of 2,98222. Responsive Images and MediaFree lesson

Image Source Naming Conventions

Organizing and naming multiple image variants for maintainability and clarity.

Image Source Naming Conventions

What you'll learn: How to organize and name your multiple image variants so your responsive image code stays maintainable and clear.

Why Naming Matters

When you're using srcset with multiple image sizes (like hero-400w.jpg, hero-800w.jpg, hero-1200w.jpg), consistent naming becomes essential. Without a clear system, you'll struggle to find files, make mistakes in your HTML, and confuse team members.

A Standard Pattern

The most common and effective pattern includes:

  1. Base name: Describes the image content (hero, product-photo, team-header)
  2. Width or descriptor: The actual pixel width or device pixel ratio (400w, 800w, 2x)
  3. File extension: Standard format (.jpg, .webp, .png)

Example Structure

hero-400w.jpg    (smallest variant)
hero-800w.jpg    (medium variant)
hero-1200w.jpg   (large variant)
hero-1600w.jpg   (extra-large variant)

Think of it like a filing system: all variants of the same image stay grouped alphabetically, and the width tells you instantly what it is.

Best Practices

  • Use the actual width: 800w in the filename should match an 800-pixel-wide image
  • Be consistent: Don't mix product-sm.jpg and hero-400w.jpg patterns
  • Avoid spaces: Use hyphens (team-photo-800w.jpg) not underscores or spaces
  • Sort naturally: Names like img-1, img-2 alphabetize correctly, while img-10 won't without zero-padding

Folder Organization

Many projects use a folder structure:

/images/hero/400w.jpg
/images/hero/800w.jpg

This works when you have many variants, but flat naming (hero-400w.jpg) is simpler for most projects.

Key Takeaway: Consistent, descriptive naming with embedded width information (like imagename-800w.jpg) makes responsive images easier to manage, debug, and maintain across your entire project.