I saw last post similar to my question HTML5 canvas style height vs attribute height
But in that post, there was no clear information regarding which one will work and
For most html elements, width
attribute has nothing to do with the element's width. What defines an element's style(certainly contain width
) is the element's style
attribute.
In other words, the style.width
(style="width: 200px;"
) attribute determines the element's width.
But some elements like canvas
, svg
, the width
attribute will determines the element's width, if you don't set style.width
attribute. In this case, width="200px"
is the same as width="200"
because most browsers use the px
as default unit.
PS:
width
is invalid to set the select
's width.width
attribute is valid. You can access it and change it with freedom. You can use it to do other things.