skip to Main Content

can we give attributes to <br> and other empty elements except <hr>.

like in <hr> we can give style properties and in html documentation they wrote All HTML elements can have attributes
so <br> also have any attributes as <br> element is empty element.

2

Answers


  1. According to MDN docs:

    This element’s attributes include the global attributes.

    So, the answer is yes, we can give it attributes.

    Login or Signup to reply.
  2. yes, Expect for tag <hr> it is possible to give the attribute to all the empty tags including <br>. the reason we cannot give <hr> tag attribute is because it displays a line in html page, which cannot take any data or text. for more information, you should refer to documentation like MDN documentation

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search