2024-01-04
HTML5 interactive elements
HTML5 Interactive Elements: An Overview and Usage Guide
HyperText Markup Language (HTML) is the standard markup language for documents designed to be rendered in a web browser. Over the years, HTML has evolved to keep up with the growing need for better structure and interactivity.
HTML5, the latest version, introduces several interactive tags or elements, which makes building interactive, dynamic web content easier without having to resort to JavaScript or CSS. Let's dive into these interactive elements and have a look at some examples to understand their usage better.
The <details>
and <summary>
Elements
The <details>
and <summary>
tags allow us to create an interactive widget that the user can open or close. The <summary>
tag is a child of the <details>
tag, representing the summary or brief description of the content in <details>
.
<details>
<summary>The Solar System</summary>
<p>The Solar System includes the Sun, the Earth (where you are now!) and all the other planets.</p>
</details>
The Solar System
The Solar System includes the Sun, the Earth (where you are now!) and all the other planets.
The <dialog>
Element
The <dialog>
element presents content in a dialogue box or a window. You can toggle the visibility of the <dialog>
by changing the 'open' attribute.
<dialog open>
This is a dialog box!<br>
<button onclick="this.parentElement.close()">Close</button>
</dialog>
The <datalist>
Element
The <datalist>
element permits the creation of pre-defined options for an <input>
element. User can either select an option or type in their input.
<label for="browsers">Choose a browser from the list:</label>
<input list="browsers" name="browser" id="browser">
<datalist id="browsers">
<option value="Chrome">
<option value="Firefox">
<option value="Internet Explorer">
<option value="Opera">
<option value="Safari">
</datalist>
## The `
Tags:
html5