#2 RazorBlade Fluent Tag API @Tag.Img().Src(...) and Srcset(...) v3
RazorBlade Fluent Tag API @Tag.Img().Src(...)
and Srcset(...)
v3
One of the magic bits of the Html5 tags is that they are smart. For example, url properties like Src()
or Href()
will safely encode if they are not yet encoded. This is super important for CMS solutions where the image file may easily contain umlaut characters or spaces.
Note that it's Srcset()
and not SrcSet
. For consistency, everything is always lower case.
⬇️ Result | Source ➡️
<img src='/oqtane-tutorials/app/Tutorial-Razor/assets/tutorials/razorblade-img/img/%C3%BCberschrift-small.png?name=%E6%94%B9%E5%96%84'>
picture
tags are the future of img
tags. But it can be messy to create them, so here goes 😉. This example will return a small image if your screen is small, a large one otherwise. Try resizing the width of your browser to test. The image will become blurry if the browser is less than 800px wide.
⬇️ Result | Source ➡️
<picture><source srcset='/oqtane-tutorials/app/Tutorial-Razor/assets/tutorials/razorblade-img/img/%C3%BCberschrift-large.png' media='(min-width: 800px)'><img src='/oqtane-tutorials/app/Tutorial-Razor/assets/tutorials/razorblade-img/img/%C3%BCberschrift-small.png'></picture>
#2 RazorBlade Fluent Tag API @Tag.Img().Src(...) and Srcset(...) v3