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 reversed Attribute
Photo Credit to CodeToFun
🙋 Introduction
The reversed
attribute in HTML is used in ordered lists (<ol>) to reverse the order of the list items.
When applied, it causes the list items to be numbered in descending order, providing a unique visual presentation compared to the default ascending order.
🎯 Purpose of reversed
The primary purpose of the reversed
attribute is to change the numbering direction of list items within an ordered list.
By default, list items in an <ol> are numbered sequentially starting from 1. However, the reversed
attribute allows you to present information in a descending order.
💎 Values
The reversed
attribute accepts a Boolean value:
- reversed="reversed": This value indicates that the list items should be numbered in descending order.
- (No value): If the
reversed
attribute is present without a value, it is treated as if it has the value "reversed." Including the attribute without a value is a shorthand for reversed='reversed'.
📄 Example
Let's take a look at an example of how to use the reversed
attribute in an HTML ordered list:
<ol reversed>
<li>Third item</li>
<li>Second item</li>
<li>First item</li>
</ol>
🧠 How it Works
In this example, the reversed
attribute is applied to the <ol> element, causing the list items to be numbered in reverse order.
🔄 Dynamic Values with JavaScript
Similar to other HTML attributes, you can dynamically set the reversed
attribute using JavaScript.
This can be useful when you want to alter the list presentation based on user interactions or certain conditions. Here's a brief example:
<script>
// Dynamically set reversed attribute for an ordered list
document.getElementById("dynamicList").reversed = true;
</script>
🧠 How it Works
In this script, the reversed
attribute is set to true for an ordered list with the id dynamicList. This can be helpful when you want to dynamically change the list numbering direction.
🏆 Best Practices
- Use the
reversed
attribute when you want to present information in descending order within an ordered list. - Be aware that the
reversed
attribute is specific to ordered lists (<ol>), and applying it to other elements won't have any effect. - Test the presentation of your ordered list across different browsers to ensure consistent behavior.
🎉 Conclusion
The reversed
attribute provides a simple yet effective way to change the numbering direction of list items in an ordered list.
By understanding its usage and incorporating it into your HTML documents, you can create visually appealing and customized lists.
👨💻 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 reversed Attribute), please comment here. I will help you immediately.