Let’s take one interactive feature apart so the markup and behavior make sense separately.
What You Need to Know
Draggable hints that an element can be dragged, but a complete drag-and-drop interaction usually needs JavaScript. Offer another way to complete the task for keyboard and touch users.
In this example: drag a list item to a different area.
Try the Example
Take a look at the example. We’ll explain the important lines right below it.
<p draggable="true" id="drag-note">Drag this practice note.</p>
<p>Moving data into a drop zone still needs JavaScript event handlers.</p>
Let’s Read the Code
- id: An id uniquely identifies an element on this page.
- Read from the outside inward: the outer element describes the job, while the nested elements supply the information.
Read the named elements and attributes together. They explain how the browser connects this feature to the rest of the page.
What Happens in the Browser?
When this example includes JavaScript, it supplies behavior that ordinary HTML does not automatically provide. Always think about a fallback.
Start with native behavior. Details, dialog, and popover each solve a different interface problem. Choose the simplest control that actually matches what a visitor wants to do, then test focus and dismissal as well as appearance.
Your Turn
Run this on a local development server if it loads modules or resources. Change the visible text or trigger and check what still works with scripts disabled.
Common Beginner Mistakes
- Assuming new HTML syntax works in every browser without testing.
- HTML supplies structure; JavaScript is necessary for the scripted behavior in this example. Check keyboard access and focus movement too.
Key Takeaways
- Draggable hints that an element can be dragged, but a complete drag-and-drop interaction usually needs JavaScript.
- id: An id uniquely identifies an element on this page.
- Test the behavior you expect rather than trusting how the snippet looks in your editor.