News for hackers. Stuff that matters.
Re:Just Use a Button by cassepipe on Friday October 31, 2025 @02:26PM (#45775119)
Is is not okay to wrap a link inside a button ? I guess not

Which elements are allowed to wrap which is unclear to me

Re:Just Use a Button by stevula on Friday October 31, 2025 @02:39PM (#45775243)
What is the use case? It’s hard for me to think of a reason you’d want to wrap a link in a button. If you want to navigate, use an anchor. If you want to trigger JS logic, use a button with onclick handler. If you want to navigate while doing some side effect like an API call, use an anchor with onclick handler (and don’t prevent default).
Re:Just Use a Button by cferdinandi on Friday October 31, 2025 @03:45PM (#45775937)
Literally absolutely never ever do this.
Re:Just Use a Button by Shog9 on Friday October 31, 2025 @05:07PM (#45776709)
FWIW, you can generally figure out what's allowed fairly quickly by checking the content model for a given element[1]. Some browsers might be more or less restrictive, but for normal usage this'll be more than enough to avoid unexpected behavior.

[1]: https://html.spec.whatwg.org/#the-button-element:concept-ele...

Re:Just Use a Button by phatskat on Monday November 03, 2025 @09:51AM (#45799610)
MDN includes a “Permitted Content” section for elements, eg for button it says

> Phrasing content but there must be no Interactive content. If the <button> is the first child of a customizable select element, then it may also contain zero or one <selectedcontent> element.

“Ok, but what constitutes ‘phrasing content’ or ‘interactive content’?” you might ask. Those terms are links that give a very good overview of their constituent elements.