Simple Methods of Using Interactive Elements in HTML

Simple Methods of Using Interactive Elements in HTML: To begin, first refer – interactive-elements

Using the DETAILS and SUMMARY Elements

Content can be hidden or shown using a disclosure widget created using HTML and components. Your desired content is housed in the element, while the <summary> element acts as a visible header or label. This is a basic example of how to make an expanding section on a webpage using the <details> and <summary> elements:

Figure 1 – Showing the use of the DETAILS and SUMMARY Elements

In this case, the summary that is initially displayed is the text that says “Click to expand”. It will disclose the secret paragraph when you click on it. The information is labeled or headed by the <summary> element, while the <details> element serves as a container for the content that can be shown or hidden.

Using the COMMAND Element

Before HTML5, the <command> element was used in former versions of HTML to define commands that users could access via a toolbar or menu. However, it should not be utilized in contemporary web development, as it is now obsolete. You may accomplish similar functionality by handling user interactions with JavaScript and event handlers instead of the <command> element. Both the <menu> and <command> elements are deprecated in HTML5 and are not supported by contemporary browsers. It was included in an earlier iteration of the HTML specification, but more recent methods of generating interactive elements—like buttons, links, and JavaScript frameworks and libraries—have taken its place.

You may accomplish equivalent functionality with⁣ <button> elements with event listeners or⁣ <a> elements with suitable styling and JavaScript capability instead of the <command> element. This is an illustration utilizing <button> elements:

Figure 2 – Showing the use of the COMMAND Element

In this instance, pressing the “Save” or “Delete” buttons will cause the corresponding actions to be performed. More adaptability and compatibility with contemporary web standards are offered by this method.

Using the MENU Element

In earlier iterations of HTML, menus were created using the <menu> and <menuitem> elements. Nevertheless, HTML5 deprecated both elements, so it is advised to create menus using more contemporary techniques, including lists (<ul> and <li> elements) styled with CSS or more complex interactions utilizing JavaScript tools. This is an illustration of how you could have utilized the <menu> elements:

Figure 3 – Showing the use of the MENU Element

Using the KBD Element

HTML’s <kbd> element indicates keyboard input, such as keystrokes or keyboard shortcuts. Here’s an example of how you can use the <kbd> element to show a keyboard shortcut:

Figure 4 – Showing the use of the KBD Element

In this example, the text “Ctrl” and “S” inside the <kbd> elements indicate that the user should hit the Control and S keys simultaneously to save their work. The <kbd> element is generally designed to look like it’s displaying keyboard keys with a monospaced font.

Using the TIME Element

The <time> element in HTML represents dates and times in machine-readable format. It can also be used to represent the duration or timing of an event. Here’s an example of using the <time> element to display a date:

Figure 5 – Showing the use of the TIME Element

The <time> element is used in this example to display a concert’s start time. The datetime attribute represents the date and time in machine-readable format (ISO 8601), while the <time> element has a human-readable representation of the time. The <time> element can express durations or specific periods based on the context.

Scroll to Top