[go: up one dir, main page]

DEV Community

Mrinalini Sugosh (Mrina) for TinyMCE

Posted on • Edited on

10 HTML Features You Need to Know

Working with TinyMCE—a rich text editor (RTE) that directly interacts with the DOM and converts content into HTML—I've come to realize that HTML is more than just the basics like <div>, <p>, and <img>. There are several advanced features that can significantly enhance our web development projects, improving not only functionality but also accessibility and security. Unfortunately, many of us overlook these powerful tools. That's why I've put together a list of 10 HTML features you might not be usingm but should definitely consider incorporating into your work.

1. Template Element

I've found the <template> element incredibly useful for defining reusable HTML that isn't rendered until needed. It's great for managing dynamic content more efficiently. Since the content inside <template> isn't displayed until invoked, it can help reduce the initial page load and improve performance.

Example:

<template id="myTemplate">
    <div class="modal">
        <p>Template content goes here.</p>
    </div>
</template>
Enter fullscreen mode Exit fullscreen mode

Security Tip: When I use the <template> element to inject content dynamically, I always ensure that the content is sanitized to prevent XSS (Cross-Site Scripting) attacks.

2. Mark Element

To highlight important text, I use the <mark> element. It's a simple but effective way to draw attention to key points in content. For users with assistive technologies, like screen readers, the <mark> element helps emphasize important information within the text.

Example:

<p>The term <mark>highlighted</mark> is important in this context.</p>
Enter fullscreen mode Exit fullscreen mode

Accessibility Tip: The <mark> element is automatically announced by screen readers, so it's a good way to ensure key information isn't missed by users relying on these technologies.

3. Picture Element

When I want to ensure images are responsive and look great on all devices, I turn to the <picture> element. It allows me to specify multiple image sources, so I can serve the most appropriate one based on the user's device. It's essential for improving load times and user experience.

Example:

<picture>
    <source media="(min-width: 800px)" srcset="large.jpg">
    <source media="(min-width: 400px)" srcset="medium.jpg">
    <img src="small.jpg" alt="Responsive Image">
</picture>
Enter fullscreen mode Exit fullscreen mode

Accessibility Tip: I always include the alt attribute for images, ensuring that all users can understand the content, even if they cannot see the image.

4. Details and Summary Elements

To create expandable content sections, I use the <details> and <summary> elements. They're perfect for FAQs or collapsible sections, helping keep web pages clean and user-friendly. These elements also enhance accessibility by allowing users to control the display of additional content without relying on JavaScript.

Example:

<details>
    <summary>More Information</summary>
    <p>This is the hidden content that will be revealed when you click on "More Information".</p>
</details>
Enter fullscreen mode Exit fullscreen mode

Accessibility Consideration: The <details> and <summary> elements provide a semantic way to create collapsible content, ensuring that assistive technologies correctly interpret the relationship between the summary and the details.

5. Dialog Element

The <dialog> element is a native way to create modals without relying on external JavaScript libraries. I find it perfect for alerts, confirmation dialogs, or custom pop-ups. Beyond its ease of use, the <dialog> element is more accessible than many custom modal implementations, as it's designed with built-in focus management.

Example:

<dialog id="myDialog">
    <p>This is a modal dialog</p>
    <button >"document.getElementById('myDialog').close()">Close</button>
</dialog>

<button >"document.getElementById('myDialog').showModal()">Open Dialog</button>
Enter fullscreen mode Exit fullscreen mode

Accessibility Consideration: The <dialog> element automatically manages focus when it opens, which is crucial for users navigating with a keyboard or screen reader.

6. Output Element

I use the <output> element to display results of calculations or user interactions directly within forms. It's a straightforward way to enhance form interactivity without heavy JavaScript and ensures that assistive technologies can correctly interpret the content.

Example:

<form >"result.value=parseInt(a.value)+parseInt(b.value)">
    <input type="number" id="a" value="0"> +
    <input type="number" id="b" value="0">
    = <output name="result" for="a b">0</output>
</form>
Enter fullscreen mode Exit fullscreen mode

Accessibility Consideration: The <output> element can be programmatically linked to form elements, allowing screen readers to announce the result as it changes.

7. Data Element

The <data> element helps me associate machine-readable values with human-readable content. This is particularly useful for SEO and making content more understandable for search engines, which can then present it more accurately in search results.

Example:

<p>Price: <data value="49.99">$49.99</data></p>
Enter fullscreen mode Exit fullscreen mode

Security Note: When displaying data linked to backend systems, I ensure that the data presented is sanitized and free from vulnerabilities that could expose sensitive information.

8. Meter Element

If I need to represent a measurement within a known range, I use the <meter> element. Whether it's disk usage or progress tracking, it provides a clear, visual representation. The <meter> element is also accessible, offering an easy-to-understand display of numeric values for all users.

Example:

<meter value="70" min="0" max="100">70%</meter>
Enter fullscreen mode Exit fullscreen mode

Accessibility Tip: I always provide context around the <meter> element, so that users with assistive devices understand what the measurement represents.

9. Time Element

To accurately represent dates and times, I use the <time> element. This not only makes content more accessible but also enhances how search engines interpret temporal data. It's especially important for screen readers.

Example:

<time datetime="2024-08-15">August 15, 2024</time>
Enter fullscreen mode Exit fullscreen mode

Accessibility Tip: Using the datetime attribute provides a machine-readable format, which can be easily interpreted by assistive technologies.

10. Progress Element

The <progress> element lets me display the completion progress of tasks like downloads or submissions. It's a straightforward way to offer real-time feedback to users and ensures that assistive technologies can announce progress updates.

Example:

<progress value="70" max="100">70%</progress>
Enter fullscreen mode Exit fullscreen mode

Accessibility Consideration: Pairing the <progress> element with an aria-label or similar attribute provides context to users of screen readers about what the progress represents.

I'd love to hear how these tips help improve your workflow. Want to explore more tips and enhance your content creation experience? Check out the TinyMCE blog for insights, best practices, and tutorials, or start your journey with TinyMCE by signing up for a 14-day free trial today!

Top comments (10)

Collapse
 
mkalioby profile image
Mohamed M El-Kalioby

Nice, but was nicer to attach an example of each, but for sure, I'll try these tags.

Collapse
 
plutonium239 profile image
plutonium239

A tip: while using the <dialog> element, you don't need to have the close button specifying an on click. Instead, just put the close button inside a <form method="dialog"> … </form> element, and html handles it for you.

Collapse
 
ted_lee_2697 profile image
Ted Lee

Interesting ideas! Thanks for sharing :)

Collapse
 
edder_jprezhernndez_ profile image
Edder J. Pérez Hernández

💫

Collapse
 
rarebird15 profile image
Lanie Carmelo

As a blind person who knows HTML and is learning JavaScript, and who wants to code accessible software, I find this to be very helpful, and I love that you discuss accessibility.

Collapse
 
mrinasugosh profile image
Mrinalini Sugosh (Mrina)

Thanks Lanie!

Collapse
 
edder_jprezhernndez_ profile image
Edder J. Pérez Hernández

Collapse
 
nosnetrom profile image
Jim Mortenson

How would you implement <template>?

Collapse
 
tdjdev profile image
Davy TISSOT

With JavaScript, you can use <template> elements to swiftly generate blocks of HTML. For example:

<template id="myTemplate">
  <div>
    <p>This is a template.</p>
  </div>
</template>

<script>
  const template = document.getElementById('myTemplate');
  const clone = template.content.cloneNode(true);
  document.body.appendChild(clone);
</script>
Enter fullscreen mode Exit fullscreen mode
Collapse
 
alefeufei profile image
Alexandre Lima

Há alguma página com essas tags empregadas pra vermos o funcionamento?