Details Tag in HTML5



The <details> tag is a new tag in HTML 5. The <details> tag specifies additional information or controls about documents that the user can view or hide on demand. The contents of the details tag is hidden by default. The header is visible and could show when the user clicks on the header portion of <details> tag. The contents of the details tag are made visible by adding an open attribute to the <details> tag. The tag can also be used along with the summary tag to make your own header so that the user can expand or collapse the details of the document when required. This tag is only supported by Chrome.

Syntax

<
details open="open">
    <
summary></summary>
         <
p> </p>
</
details>

Element-Specific Attribute
Attributes Values Description
open open This Boolean attribute specifies whether the details of the data should be shown to the user or not.

HTML5 Event Attributes

onabort onblur oncanplay
oncanplaythrough onchange onclick
oncontextmenu ondblclick ondrag
ondragend ondragenter ondragleave
ondragover ondragstart ondrop
ondurationchange onemptied onended
onerror onfocus onformchange
onforminput oninput oninvalid
onkeydown onkeypress onkeyup
onload onloadeddata onloadedmetadata
onloadstart onmousedown onmousemove
onmouseout onmouseover onmouseup
onmousewheel onpause onplay
onplaying onprogress onratechange
onreadystatechange onscroll onseeked
onseeking onselect onshow
onstalled onsubmit onsuspend
ontimeupdate onvolumechange onwaiting

Code

<!DOCTYPE html>
<
html>
<
head>
    <title></title>

</
head>
<
body>
    <details>
        <summary>Csharpcorner</summary>
        <p>
            This is good website to improve your knowledge</p>
    </details>
    <br /><br />
    <details>
        <summary>Our Network</summary>
        <a href="http://www.dotnetheaven.com/">.NET Heaven</a>
        <br />
        <a href="http://www.c-sharpcorner.com/">C# Corner</a>
        <br />
        <a href="http://www.dbtalks.com/">DbTalks</a>
        <br />
        <a href="http://www.interviewcorner.com/">Interview Corner</a>
        <br />
        <a href="http://www.longhorncorner.com/">Longhorn Corner</a>
        <br />
        <a href="http://www.mindcracker.com/">Mindcracker</a>
        <br />
        <a href="http://www.vbdotnetheaven.com/">VB.NET Heaven</a>
        <br />
    </details>
    <br /><br /><br />
    <details open="open">
        <summary >Csharpcorner</summary>
        <p>
            This is good website to improve your knowledge</p>
    </details>
    <br /><br /><br />
    <details >
        <summary >Calendar</summary>
       <img src="Image/img.gif" alt="detail tag" />
    </details>
    <br />

</
body>
</
html>

Output

Chrome

<details> tag

Figure 1

As you have seen the third detail tag shows it's content by default because in the code, I have set the open value for its open attribute.

When you click on Csharpcorner or the Our Network header, the content of the detail tag will display like the following figure 2.

<details> tag

Figure 2

Click on Calendar then the image is displayed as content in the detail tag (see the following figure 3).

<details> tag

Figure 3