Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should <button> contain nested DOM element or not?

I did not realize is it bad or not, according to the W3C rules about HTML semantic writing - how we should write the button element with descended elements?

In way, like this one:

<button>
 <div>
   <span>'hi'</span>
 </div>
</button>

or only this:

<button>'hi'</button>
like image 780
Max Travis Avatar asked Dec 24 '22 03:12

Max Travis


1 Answers

I tested your code in W3C Validator & the error shown is

Element div not allowed as child of element button in this context. (Suppressing further errors from this subtree.)

W3C Validator result

like image 149
brk Avatar answered Jan 07 '23 05:01

brk