dir
The old HTML <dir> element was intended for directory-style lists. It is obsolete and should not be used in new pages; use <ul> and <li> instead.
What you will learn
- Why the
direlement is obsolete - How to translate old directory-list markup to
ulandli - Why this element is different from the writing-direction
dirattribute
Do not use dir for new lists
The element was an early HTML way to display a list of directory entries. It does not provide a useful modern semantic distinction from an unordered list and has inconsistent browser and accessibility behavior.
<!-- Historical markup: do not copy into a new page -->
<dir>
<li>Reports</li>
<li>Images</li>
</dir>
Use ul and li instead
<ul>
<li><a href="reports/">Reports</a></li>
<li><a href="images/">Images</a></li>
</ul>
Use ul for an unordered collection, ol when order matters, and dl for term-and-description pairs. Choose the list based on meaning rather than its visual style.
Do not confuse the element with the dir attribute
The obsolete dir element is unrelated to the current global dir attribute, which controls writing direction with values such as ltr, rtl, or auto.
<p dir="rtl">Right-to-left text</p>
Common mistakes
- Using
dirbecause an old tutorial calls it an HTML list element. - Confusing the obsolete element with the writing-direction attribute.
- Choosing a list element for its default bullets instead of its meaning.
- Assuming CSS can make obsolete markup a reliable semantic structure.