--- url: "https://web.dev/learn/html/apis" titulek: "HTML APIs | web.dev" h1: "HTML APIs Stay organized with collections Save and categorize content based on your preferences." popis: "Learn how HTML information can be exposed and manipulated using JavaScript." jazyk: "en" kanonicka: "https://web.dev/learn/html/apis" drobecky: ["web.dev", "Resources", "HTML"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 00:54:41" znaku: 16581 slov: 1652 kodovani: "iso-8859-2" sha256: "c193ad8ef99b187670666451f801b4943def51155bf22211579f9989d8b30b5f" --- HTML APIs Stay organized with collections Save and categorize content based on your preferences. In the introduction to this series it says "HTML elements are the nodes that make up the [Document Object Model](https://developer.mozilla.org/docs/Web/API/Document_Object_Model)." We've discussed the type of element nodes. In this section we discuss element APIs that enable querying those nodes. The DOM and AOM The DOM is an API for accessing and manipulating documents. The DOM is the tree of all the nodes in the document. Some nodes can have children, others can't. The tree includes elements, along with their attributes, and text nodes. Browser tools don't provide tree visualizations like the one above, but you can see the nodes in the element inspector. The tree representation that can be inspected in browser developer tools is the [accessibility tree](/learn/accessibility/aria-html#the_accessibility_tree). The AOM is based off the DOM; similarly, the accessibility tree contains objects representing all the markup elements, attributes, and text nodes: HTML Element APIs The middle letter of DOM is "object." Just like the `person` or `car` object example from most intro to object-oriented programming classes, every node in the document tree is an object that can be manipulated with JavaScript. The browser provides numerous APIs providing natively supported methods, events, and property querying and updating. Element nodes contain information about all the attributes set on the element. You can use HTML interfaces to access information about an element's attributes. For example, we can use [`HTMLImageElement.alt`](https://developer.mozilla.org/docs/Web/API/HTMLImageElement/alt) get the `alt` attributes of all the images: `let allImages = document.querySelectorAll('img'); allImages.forEach((imageInstance) => { console.log(imageInstance.alt); });` HTML interfaces provide more than just access to an element's attributes; you can access a lot more information. We can find the read-only [`HTMLElement.offsetHeight`](https://developer.mozilla.org/docs/Web/API/HTMLElement/offsetHeight) to get the height of each section in our page, relative to the layout. `let allSections = document.querySelectorAll('section'); allSections.forEach((sectionInstance) => { console.log(sectionInstance.offsetHeight); });` If the user changes their device orientation or otherwise changes the width of the viewport, the height of each `
` will change and the DOM properties will automatically update with it. The HTML interface APIs is not limited to accessing attribute values. The DOM provides insight into the current state of the UI. HTML APIs can access all of that information. You can access the length of a video, where a view is in the current playback, and if the video (or audio) has finished playing with [`HTMLMediaElement.duration`](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/duration), [`HTMLMediaElement.currentTime`](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/currentTime), and [`HTMLMediaElement.ended`](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/ended) respectively. Available element interfaces Most HTML element we've covered thus far in this series and have yet to cover, other than some [sectioning elements](/learn/html/headings-and-sections), have an associated DOM interface. The base interface for all elements is aptly named [Element](https://developer.mozilla.org/docs/Web/API/Element). The [`HTMLElement`](https://developer.mozilla.org/docs/Web/API/HTMLElement) inherits from Element and all HTML element-specific interfaces inherit from it. Some element-specific interfaces are implemented by multiple, similar elements. The interfaces include: [`HTMLAnchorElement`](https://developer.mozilla.org/docs/Web/API/HTMLAnchorElement) - `` [`HTMLAreaElement`](https://developer.mozilla.org/docs/Web/API/HTMLAreaElement) - `` [`HTMLAudioElement`](https://developer.mozilla.org/docs/Web/API/HTMLAudioElement) - `