Remove width and height attributes of images
Scope
The following widgets automatically generate an img HTML tag with height and width attributes.
- The MVC widgets Image widget when used with the Image dimensions template
- The MVC Image gallery widget
- The .NET Core Image widget
If you have complex page designs, you may want to remove these attributes to avoid altering them in unexpected ways.
You can do this for the MVC Image and Image gallery widgets. You cannot remove the automatic generation of width and height for the .NET Core Image widget. To do this, you need to modify the widget’s views. Perform the following:
For the MVC Image widget
- Open your Sitefinity CMS solution in Visual Studio.
- Navigate to the Image widget views.
By default, it is namedImageDimensions.cshtmland stored in~/ResourcePackages/Bootstrap4/MVC/Views/Image. - Open the
.cshtmlfile containing the view that you want to modify - Delete the following code lines:
@Html.GetWidthAttributeForImage(Model) @Html.GetHeightAttributeForImage(Model) - Make sure that the
.cshtmlfile is valid.
For the Image Gallery widget
The width and height attributes are in all templates of the Image Gallery widget. To remove them, delete the helper methods from your template.
To do this, perform the following:
- Open your Sitefinity CMS solution in Visual Studio.
- Navigate to the Image Gallery widget views.
By default, it is stored in~/ResourcePackages/Bootstrap4/MVC/Views/ImageGallery. - Open the
.cshtmlfile containing the template that you want to modify. - Delete the code lines containing code similar to the following. The actual model names differ in the different
.cshtmlfiles:
@Html.GetWidthAttributeForImage(ViewModel.Width) @Html.GetHeightAttributeForImage(ViewModel.Height) - Make sure that the
.cshtmlfile is valid.
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
Get started with Integration Hub | Sitefinity Cloud
This free lesson teaches administrators, marketers, and other business professionals how to use Sitefinity Integration Hub to create automated workflows between Sitefinity and other business systems.
Web Security for Sitefinity Administrators
This free lesson teaches administrators the basics about protecting your Sitefinity instance and your sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
Foundations of Sitefinity ASP.NET Core Development
The free on-demand video course teaches developers how to use Sitefinity ASP.NET Core and take advantage of its decoupled architecture and modern development model.