Skip to main content

Razor Blade Tutorials

Tutorial Home
#5 Picture Tags for various sizes / resolutions 

RazorBlade Fluent Tag API @Tag.Picture() with many sources v3

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.


@Tag.Picture(
  Tag.Source().Srcset(path + large).Media("(min-width: 800px)"),
  Tag.Img().Src(path + small)
)
<picture><source srcset='/Portals/0/2sxc/Tutorial-Razor/blade/assets/tag-img/%C3%BCberschrift-large.png' media='(min-width: 800px)'><img src='/Portals/0/2sxc/Tutorial-Razor/blade/assets/tag-img/%C3%BCberschrift-small.png'></picture>

<pre>@Tag.Picture(
  Tag.Source().Srcset(path + large).Media("(min-width: 800px)"),
  Tag.Img().Src(path + small)
).ToString()</pre>
#5 Picture Tags for various sizes / resolutions 

Source Code of this file

Below you'll see the source code of the file. Note that we're just showing the main part, and hiding some parts of the file which are not relevant for understanding the essentials. Click to expand the code

@inherits Custom.Hybrid.Razor14
@using ToSic.Razor.Blade;
<!-- unimportant stuff, hidden -->
RazorBlade Fluent Tag API... <!-- unimportant stuff, hidden -->
<hr>
@{
  var path = App.Path + "/blade/assets/tag-img/";
  var small = "überschrift-small.png";
  var large = "überschrift-large.png";
}

@Tag.Picture(
  Tag.Source().Srcset(path + large).Media("(min-width: 800px)"),
  Tag.Img().Src(path + small)
)


<!-- unimportant stuff, hidden -->