HTML Basic
HTML Reference
- HTML Tags
- HTML Deprecated Tags
- HTML Events
- HTML Attributes
- accept
- accept-charset
- accesskey
- action
- align
- alt
- as
- async
- autocomplete
- autofocus
- autoplay
- bgcolor
- border
- charset
- checked
- cite
- class
- color
- cols
- colspan
- content
- contenteditable
- controls
- coords
- data
- data-*
- datetime
- default
- defer
- dir
- dirname
- disabled
- download
- draggable
- enctype
- enterkeyhint
- for
- form
- formaction
- headers
- height
- hidden
- high
- href
- hreflang
- http-equiv
- id
- inert
- inputmode
- ismap
- kind
- label
- lang
- list
- loop
- low
- max
- maxlength
- media
- method
- min
- multiple
- muted
- name
- novalidate
- onabort
- onafterprint
- onbeforeprint
- onbeforeunload
- onblur
- oncanplay
- oncanplaythrough
- onchange
- onclick
- oncontextmenu
- oncopy
- oncuechange
- oncut
- ondblclick
- ondrag
- ondragend
- ondragenter
- ondragleave
- ondragover
- ondragstart
- ondrop
- ondurationchange
- onemptied
- onended
- onerror
- onfocus
- onhashchange
- oninput
- oninvalid
- onkeydown
- onkeypress
- onkeyup
- onload
- onloadeddata
- onloadedmetadata
- onloadstart
- onmousedown
- onmousemove
- onmouseout
- onmouseover
- onmouseup
- onmousewheel
- onoffline
- ononline
- onpagehide
- onpageshow
- onpaste
- onpause
- onplay
- onplaying
- onpopstate
- onprogress
- onratechange
- onreset
- onresize
- onscroll
- onsearch
- onseeked
- onseeking
- onselect
- onstalled
- onstorage
- onsubmit
- onsuspend
- ontimeupdate
- ontoggle
- onunload
- onvolumechange
- onwaiting
- onwheel
- open
- optimum
- pattern
- placeholder
- popover
- popovertarget
- popovertargetaction
- poster
- preload
- readonly
- rel
- required
- reversed
- rows
- rowspan
- sandbox
- scope
- selected
- shape
- size
- sizes
- span
- spellcheck
- src
- srcdoc
- srclang
- srcset
- start
- step
- style
- tabindex
- target
- title
- translate
- type
- usemap
- value
- width
- wrap
- HTML Global Attributes
- HTML Status Code
- HTML Language Code
- HTML Country Code
- HTML Charset
- MIME Types
HTML summary Attribute
Photo Credit to CodeToFun
🙋 Introduction
The summary
attribute in HTML is used to provide a summary or caption for table elements. This attribute was intended to describe the structure or purpose of a table, mainly for accessibility reasons, so that screen readers can convey this information to users with visual impairments.
However, it's important to note that the summary
attribute has been deprecated in HTML5. Modern HTML practices encourage using alternative methods like ARIA attributes for accessibility.
🎯 Purpose of summary
The main purpose of the summary
attribute is to offer a textual description of the table's content and structure. This is particularly useful for assistive technologies, helping users understand the context and purpose of the data presented in a table.
💎 Values
The summary
attribute can take any string value that describes the table. Since it is a descriptive attribute, its value should be concise yet informative.
📄 Example:
<table summary="This table lists the quarterly sales figures for the year 2023.">
<thead>
<tr>
<th>Quarter</th>
<th>Sales</th>
</tr>
</thead>
<tbody>
<tr>
<td>Q1</td>
<td>$10,000</td>
</tr>
<tr>
<td>Q2</td>
<td>$15,000</td>
</tr>
<tr>
<td>Q3</td>
<td>$20,000</td>
</tr>
<tr>
<td>Q4</td>
<td>$25,000</td>
</tr>
</tbody>
</table>
🧠 How it Works
In this example, the summary
attribute provides a brief description of the table's contents, which can help users understand what the table represents.
🔄 Dynamic Values with JavaScript
Although the summary
attribute is deprecated, you can still dynamically set or modify it using JavaScript in legacy systems or for educational purposes. Here's how you can do it:
<script>
// Dynamically set the summary attribute for a table
document.getElementById("salesTable").setAttribute("summary", "Dynamically added summary describing the sales table.");
</script>
<table id="salesTable">
<thead>
<tr>
<th>Quarter</th>
<th>Sales</th>
</tr>
</thead>
<tbody>
<tr>
<td>Q1</td>
<td>$10,000</td>
</tr>
<tr>
<td>Q2</td>
<td>$15,000</td>
</tr>
<tr>
<td>Q3</td>
<td>$20,000</td>
</tr>
<tr>
<td>Q4</td>
<td>$25,000</td>
</tr>
</tbody>
</table>
🧠 How it Works
In this script, the summary
attribute is dynamically set for the table with the id "salesTable."
🏆 Best Practices
- Since the
summary
attribute is deprecated in HTML5, it's recommended to use other methods for adding accessible descriptions to tables. Consider using ARIA attributes like aria-describedby or providing detailed captions within the table content itself. - Ensure any descriptive text added to your tables is clear and concise to benefit users of assistive technologies.
- Test your tables with various screen readers and accessibility tools to ensure they convey the intended information effectively.
🎉 Conclusion
While the summary
attribute was designed to improve table accessibility, it has been deprecated in modern HTML. Instead, use ARIA attributes and other accessible practices to ensure your tables are understandable to all users.
Understanding the legacy use of summary can still be valuable, particularly when maintaining or updating older websites.
👨💻 Join our Community:
Author
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
If you have any doubts regarding this article (HTML summary Attribute), please comment here. I will help you immediately.