HTML APIs
HTML APIs
HTML APIs allow web applications to interact with browser features and devices.
What is an API?
API stands for Application Programming Interface.
Browsers provide built-in APIs that developers can use with JavaScript.
Common HTML APIs
Geolocation API
Gets the user's current location.
Drag and Drop API
Allows dragging and dropping elements.
Web Storage API
Stores data in the browser.
Canvas API
Draws graphics using JavaScript.
Geolocation API Example
Example
navigator.geolocation
.getCurrentPosition(showPosition);
function showPosition(position){
console.log(position.coords.latitude);
}
Drag and Drop API
HTML drag and drop lets users move elements around the page.
Drag Me
Canvas API
The Canvas API is used for drawing graphics and animations.
Web Storage API
Web storage stores data in the user's browser.
| Storage Type | Description |
|---|---|
| localStorage | Stores data permanently |
| sessionStorage | Stores data temporarily |
localStorage.setItem( "name", "Mayank" );
Benefits of HTML APIs
- Create interactive websites
- Access browser features
- Store user data
- Improve user experience