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:
- Base name: Describes the image content (
hero,product-photo,team-header) - Width or descriptor: The actual pixel width or device pixel ratio (
400w,800w,2x) - 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:
800win the filename should match an 800-pixel-wide image - Be consistent: Don't mix
product-sm.jpgandhero-400w.jpgpatterns - Avoid spaces: Use hyphens (
team-photo-800w.jpg) not underscores or spaces - Sort naturally: Names like
img-1,img-2alphabetize correctly, whileimg-10won'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.