I have encountered a simple question but can’t find the answer. The question is that, when I want to use inline style, for example width and height for an element in HTML, is it better to do it by width attribute or by inline style width?
<div style="width:${widthx}; height:${heightx};"></div>
VS.
<div width="${widthx}" height="${heightx}"></div>
what about one of them being deprecated or better for SEO solutions?
3
Answers
The size is about styling so you should use CSS for it, however you need to add px to define the unit of the height and width.
The MDN says regarding the height attribute:
Based on this MDN link for HTML Attributes, you should use
style
as attributes for<div>
(or elements that are not<canvas>, <embed>, <iframe>, <img>, <input>, <object>, <video>
) are considered legacy.From the linked MDN article:
Along with what others have hinted at. Using style is more appropriate, as the width attribute only exists on specific elements.
https://www.w3schools.com/tags/att_width.asp