Get to know MDN better
このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。
HTMLImageElement の currentSrc プロパティは読み取り専用で、表す <img> 要素で現在表示されている画像の URL を表します。
HTMLImageElement で表される <img> 要素の中で、現在表示されている画像の完全な URL を示す文字列です。これは、sizes や HTMLImageElement.srcset 属性を用いて複数の画像オプションを提供する場合に有用です。currentSrc を使用すると、提供された画像セットの中からブラウザーがどの画像を選択したかを判断することができます。
この例では、時計の画像に 2 種類のサイズを用意しています。一つは幅 200px で、もう一つは幅 400px です。 sizes 属性は、ビューポートが幅 400px 未満の場合は画像を文書幅の 50% で、それ以外の場合は画像を文書幅の 90% で描画することを指定しています。
| HTML # dom-img-currentsrc-dev |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025年4月12日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.