Exploring the Hidden Gems of HTML: 11 Lesser-Known Tags You Should Know

Bhoomit Ganatra - Aug 18 - - Dev Community

HTML is an incredible markup language that forms the backbone of web development. Despite its simplicity and lack of strict syntax rules like semicolons, HTML is a great starting point for anyone learning to code. It introduces concepts of proper syntax and logic, laying the groundwork for more advanced programming languages.

In the world of web development, HTML can be thought of as the skeleton that holds everything together. JavaScript serves as the organs that make the webpage functional, while CSS is the outer appearance, adding style and visual appeal. HTML's elements, or tags, tell the browser what each part of the page should do. For example, headings are marked with <h1> or <h2>, paragraphs with <p>, and containers with <div>.

While many are familiar with basic HTML tags, there are some lesser-known tags that can significantly enhance your web pages. Let's explore 10 of these hidden gems, complete with code demos.

1. <abbr> Tag: The Abbreviation Assistant

The <abbr> tag is perfect for displaying the meaning of acronyms or abbreviations. By wrapping an acronym in the <abbr> tag and adding a title attribute, you can provide additional information when users hover over the abbreviation.

Code Example:

<p>The <abbr title="HyperText Markup Language">HTML</abbr> is the standard markup language for creating web pages.</p>
Enter fullscreen mode Exit fullscreen mode

When you hover over "HTML," a tooltip will display "HyperText Markup Language."

2. <code> Tag: Displaying Code Snippets

The <code> tag is your go-to for displaying code blocks on a webpage. It automatically displays text in a monospace font, making your code snippets clear and distinct.

Code Example:

<p>To print "Hello, World!" in Python, use the following code:</p>
<code>print("Hello, World!")</code>
Enter fullscreen mode Exit fullscreen mode

This will display the Python code snippet in a monospace font.

3. <kbd> Tag: Keyboard Input Display

The <kbd> tag is used to display keyboard inputs. Wrapping keyboard keys in the <kbd> tag will display them in a monospace font, giving them the appearance of keyboard buttons.

Code Example:

<p>To save your work, press <kbd>Ctrl</kbd> + <kbd>S</kbd>.</p>
Enter fullscreen mode Exit fullscreen mode

This will show "Ctrl + S" as if they are keyboard buttons.

4. <datalist> and <option> Tags: Interactive Input Suggestions

The <datalist> tag, combined with the <option> tag, allows you to create input fields with interactive suggestions.

Code Example:

<label for="color">Choose a color:</label>
<input list="colors" id="color" name="color">
<datalist id="colors">
  <option value="Red">
  <option value="Green">
  <option value="Blue">
  <option value="Yellow">
  <option value="Black">
</datalist>
Enter fullscreen mode Exit fullscreen mode

When you start typing in the input field, a list of color options will appear.

5. <dialog> Tag: Quick and Easy Pop-ups

The <dialog> tag provides a straightforward way to create modals or pop-ups.

Code Example:

<dialog id="myDialog">
  <p>This is a simple dialog box.</p>
  <button onclick="document.getElementById('myDialog').close()">Close</button>
</dialog>
<button onclick="document.getElementById('myDialog').showModal()">Open Dialog</button>
Enter fullscreen mode Exit fullscreen mode

Clicking the "Open Dialog" button will show the dialog box, and the "Close" button will close it.

6. <details> and <summary> Tags: Native Dropdowns

The <details> and <summary> tags are perfect for creating native dropdown menus without the need for CSS or JavaScript.

Code Example:

<details>
  <summary>More Information</summary>
  <p>This is additional information that is hidden by default.</p>
</details>
Enter fullscreen mode Exit fullscreen mode

Clicking "More Information" will reveal the hidden content.

7. <time> Tag: SEO-Friendly Time Representation

The <time> tag helps search engines read time values, which can improve your website's SEO.

Code Example:

<p>The event will take place on <time datetime="2024-12-25">December 25th, 2024</time>.</p>
Enter fullscreen mode Exit fullscreen mode

This will display "December 25th, 2024" as readable text, but search engines will recognize it as a date.

8. <ruby>, <rt>, and <rp> Tags: Ruby Notation

Ruby notation can be achieved with the <ruby>, <rt>, and <rp> tags, useful for adding annotations to text.

Code Example:

<ruby>明日<rt>Ashita</rt></ruby> means "tomorrow" in Japanese.
Enter fullscreen mode Exit fullscreen mode

This will display "明日" with "Ashita" as a small annotation above it.

9. <progress> Tag: Simple Progress Bars

The <progress> tag is an easy way to create progress bars without writing any CSS.

Code Example:

<label for="file">File upload progress:</label>
<progress id="file" value="32" max="100">32%</progress>
Enter fullscreen mode Exit fullscreen mode

This will display a progress bar showing 32% completion.

10. <meter> Tag: Scalable Value Representation

The <meter> tag represents a scalar measurement, such as a score or rating.

Code Example:

<p>Test score:</p>
<meter value="0.6" min="0" max="1" low="0.3" high="0.8" optimum="0.7">60%</meter>
Enter fullscreen mode Exit fullscreen mode

This will display a meter bar, which adjusts its color based on the value.

11. <fieldset> and <legend> Tags: Grouping Form Elements

The <fieldset> and <legend> tags provide a simple way to group related form elements together.

Code Example:

<fieldset>
  <legend>Personal Information</legend>
  <label for="name">Name:</label>
  <input type="text" id="name" name="name"><br><br>
  <label for="email">Email:</label>
  <input type="email" id="email" name="email">
</fieldset>
Enter fullscreen mode Exit fullscreen mode

This will display a box labeled "Personal Information" containing the form fields.

Conclusion

These lesser-known HTML tags can add a new level of functionality and accessibility to your web pages. Whether you're creating dropdowns, displaying code snippets, or enhancing form fields, these tags offer a range of possibilities without the need for extra CSS or JavaScript. Experiment with them, and you might find yourself incorporating them into your regular web development practices.

If you found this blog helpful, be sure to share it with others and stay tuned for more tips on programming, web development, and the journey of learning to code.

Inspiration for this blog : https://www.youtube.com/watch?v=VkWJQe_EsjQ

. . . . . . . . . . .