If you want to create a button from scratch, you must first create the universe

This title could be clearer and more informative.Try out Clickbait Shieldfor free (5 uses left this month).

Building a button from scratch using a custom HTML element is a Sisyphean task that illustrates why native semantic HTML should always be preferred. The post walks through every requirement a native `<button>` satisfies — ARIA role, accessible label, focusability, mouse/touch/pointer/keyboard events, disabled state, form association, constraint validation, and event ordering — and implements each one step by step in a custom element (`<sagan-button>`). The result is nearly 500 lines of JavaScript that still only partially replicates what the browser provides for free. The conclusion is a strong call to use semantic HTML and avoid recreating native elements with ARIA and custom elements unless absolutely necessary.

•21m read time•From madcampos.dev
Post cover image
Table of contents
Newtonian laws of UXCustom element nucleiPeriodic table of ARIAThe focusable universeFundamental element interactionsJS galaxy formationCosmic Keyboard Interaction (CKI)Absolute zero: When elements become disabledElement interactionsFor every action…Event listener horizonUnexplored API spaceIn closingAppendix A - Frequently Asked Questions (FAQ)Appendix B - The final codeFootnotesShare quote
1 Comment