๐ HTML Tags You Might Not Know About
๐ก Newskategorie: Programmierung
๐ Quelle: dev.to
Hello Devs๐
In this post, I will share some new and helpful html tags which are added in HTML5 to write easy and fast code to create complex, dynamic, engaging, and effective websites.
Lets get started๐
dialog
โก Now you can easily create dialog box or a popup window with <dialog>
tag. Itโs a great way to create custom modal dialogs without relying heavily on JavaScript.
<dialog id="myDialog">
<p>This is a dialog box</p>
<button onclick="document.getElementById('myDialog').close()">Close
</button>
</dialog>
<button onclick="document.getElementById('myDialog').showModal()">Open Dialog
</button>
template
โก The <template>
tag is used as a container for holding client-side content that you donโt want to display when the page loads. This content can be cloned and inserted into the document using JavaScript.
<button onclick="showContent()">Show hidden content</button>
<template>
<h2>Hello, This is Kiran</h2>
<p>Thanks for reading this</p>
</template>
<script>
function showContent() {
let temp = document.getElementsByTagName("template")[0];
let clon = temp.content.cloneNode(true);
document.body.appendChild(clon);
}
</script>
picture
โก By using <picture>
tag you can define multiple sources for an image, now the browser choose the best one based on screen size, resolution. This is particularly useful for responsive design.
<picture>
<source media="(min-width:650px)" srcset="img_pink_flowers.jpg">
<source media="(min-width:465px)" srcset="img_white_flower.jpg">
<img src="img_orange_flowers.jpg" alt="Flowers" style="width:auto;">
</picture>
meter
โก The <meter>
tag can be used for representing a scalar measurement within a known range, like disk usage or the relevance of a query result. It helps to visually display values within a range.
<label for="diskUsage">Disk Usage:</label>
<meter id="diskUsage" value="0.6">60%</meter>
output
โก The <output>
tag represents the result of a calculation. It can be used with JavaScript to display the result of a calculation.
<form oninput="result.value=parseInt(a.value)+parseInt(b.value)">
<input type="number" id="a" value="50"> +
<input type="number" id="b" value="25"> =
<output name="result" for="a b">75</output>
</form>
progress
โก The <progress>
tag represents the completion progress of a task, such as a download or file upload.
<label for="fileProgress">File upload progress:</label>
<progress id="fileProgress" value="70" max="100">70%</progress>
mark
โก The <mark>
tag is used to highlight text. Itโs particularly useful for search result pages where you want to highlight the matching text.
<p>The word <mark>highlighted</mark> is important.</p>
abbr
โก The <abbr>
tag is used to define an abbreviation or acronym, providing a full description in the title attribute.
<p>I'm a true<abbr title="Marvel Cinematic Universe">MCU</abbr>fan.</p>
time
โก The <time>
tag is used to represent dates, times, or durations. Itโs useful for making your time-related data machine-readable.
<p>The concert starts at <time datetime="20:00">8 PM</time>.</p>
bdi
โก The <bdi>
tag is used to isolate a part of text that might be formatted in a different direction from other text outside it. It ensures that your web content remains consistent and readable, no matter what languages or text directions are involved.
<ul>
<li>Product: <bdi>ABC1234</bdi></li>
<li>Product: <bdi>ู
ุฑุญุจุง5678</bdi></li>
</ul>
wbr
โก The <wbr>
tag specifies where the text can break into a new line, if necessary. This is useful for long words or URLs.
<p>Thisisaverylongword<wbr>thatmightneedbreaking.</p>
main
โก The <main>
tag is used to specify the main content of the document. It should only be used once per page, and it excludes content that is repeated across documents like headers, footers, navigation, and sidebars.
<main>
<h1>Welcome to my blog post</h1>
<p>Today we will learn some new html tags</p>
</main>
figcaption
โก The <figcaption>
tag is used for providing a caption to the figure.
<figure>
<img src="Thanos.jpg" alt="Thanos image">
<figcaption>Thanos snapping his fingers</figcaption>
</figure>
That's it for this article.๐
Thank you for readingโค
...