Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

HTML Basic

HTML Reference

HTML kind Attribute

Posted in HTML Tutorial
Updated on Jan 24, 2024
By Mari Selvan
👁️ 20 - Views
⏳ 4 mins
💬 1 Comment
HTML kind Attribute

Photo Credit to CodeToFun

🙋 Introduction

The kind attribute is a feature in HTML used to specify the type of the media resource referenced by the <source> element within an <audio> or <video> tag.

This attribute plays a crucial role in providing information about the nature of the media content, helping browsers to handle and render it appropriately.

🎯 Purpose of kind

The primary purpose of the kind attribute is to inform the browser about the role of a particular <source> element in relation to the media resource.

This allows the browser to select the most suitable source for rendering based on factors such as codec support and device capabilities.

💎 Values

The kind attribute accepts several values to describe different types of media content. Some common values include:

  • subtitles: Denotes that the media resource is a set of subtitles or captions.
  • captions: Specifies that the media resource contains captions.
  • descriptions: Indicates that the media resource provides an audio description of the content for users with visual impairments.
  • chapters: Represents that the media resource contains chapters or table of contents information.
  • metadata: Denotes that the media resource is additional metadata, not intended to be rendered.

📄 Example

Let's look at a basic example of how to use the kind attribute within a <video> element:

kind.html
Copied
Copy To Clipboard
<video controls>
  <source src="movie.mp4" type="video/mp4" kind="captions">
  <source src="movie.vtt" type="text/vtt" kind="subtitles">
  Your browser does not support the video tag.
</video>

🧠 How it Works

In this example, the first <source> element provides captions for the video (kind="captions"), and the second <source> element provides subtitles (kind="subtitles"). The browser uses this information to select the appropriate source for rendering.

🔄 Dynamic Values with JavaScript

Similar to other HTML attributes, you can also dynamically set the kind attribute using JavaScript.

This is beneficial when you want to change the role of a media resource dynamically based on user interactions or other conditions. Here's a simple example:

kind.html
Copied
Copy To Clipboard
<script>
  // Dynamically set the kind attribute for a source element
  document.getElementById("dynamicSource").kind = "descriptions";
</script>

🧠 How it Works

In this script, the kind attribute is set to descriptions for a <source> element with the id dynamicSource. This could be useful in scenarios where you want to provide an audio description dynamically based on user preferences.

🏆 Best Practices

  • Utilize the kind attribute to provide meaningful information about the role of each <source> element within your media elements.
  • Ensure compatibility by selecting appropriate values based on the content type and user accessibility requirements.
  • Test your media elements across different browsers to ensure consistent behavior.

🎉 Conclusion

The kind attribute is a valuable tool in HTML for specifying the role of media resources within <audio> and <video> elements.

By understanding and leveraging this attribute, you can enhance the accessibility and user experience of your multimedia content.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Mari Selvan
Mari Selvan
3 months ago

If you have any doubts regarding this article (HTML kind Attribute), please comment here. I will help you immediately.

We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy