Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
HTML

HTML5: Fix a Picture Element Serving the Wrong Art Direction Source

- 30.11.26 - ErcanOPAK

🧩 Fix a Picture Element Serving the Wrong Art Direction Source

A <picture> element evaluates its <source> elements in document order and picks the first one whose media condition matches, falling through to the final <img> only if none do — putting a narrower, more specific media query after a broader one means the broader source wins first and the specific art-direction crop never gets a chance to apply at all.

🔎 The Problem

<picture>
  <source media="(min-width: 0px)" srcset="wide-crop.jpg">
  <source media="(max-width: 600px)" srcset="mobile-crop.jpg">
  <img src="wide-crop.jpg" alt="Hero banner">
</picture>
<!-- First source matches EVERY width, including mobile,
     so mobile-crop.jpg is never selected -->

✅ Fix: Order Sources From Most Specific to Least Specific

  • List narrower, more targeted media conditions first and progressively broader ones after, since the browser commits to the first match it finds in document order and never backtracks.
  • Drop the artificial (min-width: 0px) catch-all entirely and let the final <img> tag serve as the true default — that’s exactly what it’s there for.
  • Test by resizing the viewport in DevTools and checking the Network tab for which image file actually loads at each breakpoint, rather than trusting the markup order by eye.

The picture element doesn’t pick the best match — it picks the first match, so source order is the whole rule.

— Frontend Architect

Related posts:

HTML5: Real Art Direction with the  Element

HTML5: Real Art Direction with the Element

HTML5: Fix a Form That Submits on Enter From One Input but Not Another

HTML5: Fix a Form That Submits on Enter From One Input but Not Another

HTML Buttons Submit Forms Accidentally

HTML Buttons Submit Forms Accidentally

Views: 5
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

The AI Prompt That Hunts Down a Leaked Event Subscription
Asp.Net Core: Fix CORS Preflight Blocked by a Custom Header Name

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Read

  1. 01How to make theater mode the default for Youtube 1,079 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 996 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 995 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 866 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 671 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 629 views
  8. 08Average of all values in a column that are not zero in SQL 584 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 561 views
Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
Back to top
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com