HTML <dir> Tag

Beginner
⏱️ 4 min read
📚 Updated: Jun 2026
🎯 4 Examples
Legacy

What You’ll Learn

By the end of this tutorial, you’ll understand the obsolete <dir> element and the modern replacements you should use instead.

01

Historical Syntax

How <dir> listed files and folders with li children.

02

Obsolete Status

Why HTML5 removed the dir element from the specification.

03

ul Replacement

Use <ul> with <li> for directory-style lists.

04

Nested Lists

Nested ul elements for subfolder hierarchies.

05

dir Attribute

The global dir attribute for ltr/rtl text—not the tag.

06

Legacy Maintenance

Recognize dir in old HTML and migrate to modern markup.

What Was the <dir> Tag?

The <dir> element (short for “directory”) was an HTML list container for displaying file and folder names. It worked like a compact bullet list, similar to the also-obsolete <menu> element. Early HTML used it before <ul> became the standard list element.

⚠️
Obsolete in HTML5 — Use <ul>

Do not use <dir> in new websites. It is not the same as the dir attribute for left-to-right or right-to-left text. For lists, use <ul> with <li> items.

HTML5 consolidated list markup under ul. Learn <dir> to read legacy HTML, but use semantic unordered lists in all new work.

ul-replacement.html
<ul>
  <li>Documents</li>
  <li>Pictures</li>
  <li>Music</li>
</ul>

📝 Syntax (Historical)

Legacy markup wrapped li items inside dir:

syntax.html
<dir>
  <li>Documents</li>
  <li>Pictures</li>
  <li>Music</li>
</dir>
  • <dir> held <li> list items—like ul and menu.
  • The obsolete compact attribute reduced spacing—use CSS instead.
  • Do not confuse the dir element with the dir attribute.
  • Browsers may still render old dir markup for backward compatibility only.

⚡ Quick Reference

FeatureSyntax / RuleNotes
HTML5 statusObsoleteDo not use in new code
Use insteadul + liSemantic list markup
dir attributedir="ltr" / "rtl"Separate global attribute
ChildrenliList items inside dir
compact attrLegacyAlso obsolete; use CSS
Related obsoletemenuAlso replaced by ul

⚖️ <dir> Element vs dir Attribute

These share a name but serve completely different purposes:

NameTypePurpose
<dir>ElementObsolete directory list tag
dir=""AttributeSets ltr, rtl, or auto text direction
On any elementGlobalhtml, p, div, span, etc.
Still validAttribute onlyUse for RTL languages

🧰 Attributes

The obsolete <dir> element had no useful tag-specific attributes in modern HTML:

compact Obsolete

Legacy boolean attribute for tighter list spacing. Use CSS line-height or margin instead.

<dir compact>
class / id Global

Could be applied historically—prefer ul with CSS classes today.

<ul class="directory-list">
dir attribute Valid

The global dir attribute on any element sets text direction—unrelated to this tag.

dir="rtl"
Element status Obsolete

The entire <dir> element is removed from HTML5.

/* use ul instead */

The entire <dir> element is obsolete. Use ul for lists and the dir attribute for text direction.

Examples Gallery

Historical <dir> patterns plus modern ul replacements. Legacy examples are for learning only—do not use in new code.

Live Preview

Modern directory-style list using ul:

  • Documents
  • Pictures
  • Music

Legacy dir List

Historical markup only—do not use in new projects.

⚠️ Obsolete tag — for learning only.
legacy-dir.html
<dir>
  <li>Documents</li>
  <li>Pictures</li>
  <li>Music</li>
</dir>
Try It Yourself

📚 Common Use Cases (Historical)

Developers once used <dir> for file and folder listings. Today use <ul> with semantic list markup and CSS for styling.

Modern ul Replacement

The correct modern approach for directory-style lists.

directory-list.html
<ul class="directory-list">
  <li>Documents</li>
  <li>Pictures</li>
  <li>Music</li>
</ul>
Try It Yourself

Nested Folder List

Use nested ul elements for subfolders—replacing nested dir.

nested-ul.html
<ul>
  <li>File 1</li>
  <li>File 2</li>
  <li>Folder 1
    <ul>
      <li>Subfile 1</li>
      <li>Subfile 2</li>
    </ul>
  </li>
</ul>
Try It Yourself

dir Attribute (Not the Tag)

The dir attribute sets text direction—unrelated to the obsolete dir element.

dir-attribute.html
<p dir="ltr">Left-to-right: Hello, welcome.</p>
<p dir="rtl">Right-to-left: مرحبًا بكم.</p>
Try It Yourself

Styling Directory Lists with CSS

Style modern ul directory lists instead of obsolete dir markup:

list-style Bullets or none
padding Indent nested folders
line-height Compact spacing
::marker Custom list icons
directory-list.css
/* Modern directory list styling */
.directory-list {
  list-style: none;
  padding-left: 0;
}

.directory-list li {
  padding: 0.25rem 0;
  border-bottom: 1px solid #e2e8f0;
}

Live styled directory list

♿ Accessibility

Use semantic list markup and the correct direction tools:

  • Use ul for lists — screen readers announce list length and item position.
  • Use dir attribute for RTL — set dir="rtl" on content in Arabic, Hebrew, etc.
  • Do not use the dir element — it is obsolete and lacks modern semantic meaning.
  • Nest ul for hierarchy — nested lists convey folder structure to assistive tech.

🧠 Why <dir> Was Replaced

1

Early HTML used dir

dir listed files and folders with li children.

History
2

ul became the standard

One list element handles all unordered lists semantically.

HTML5
3

dir marked obsolete

New projects use ul. Browsers still render old pages.

Today
=

Use ul for lists

For text direction, use the dir attribute—not the dir tag.

Browser Support

Browsers still render obsolete <dir> for backward compatibility, but the element is not valid HTML5.

Obsolete · Use ul lists

Legacy rendering only

All major browsers still render old <dir> markup for backward compatibility, but the tag is removed from the HTML5 specification. Never use it in new projects.

95% Legacy rendering
Google Chrome Legacy render · Obsolete
Legacy render
Mozilla Firefox Legacy render · Obsolete
Legacy render
Apple Safari Legacy render · Obsolete
Legacy render
Microsoft Edge Legacy render · Obsolete
Legacy render
Internet Explorer Supported · EOL
Legacy render
Opera Legacy render · Obsolete
Legacy render

Why dir was removed

HTML5 consolidated list markup—use ul for all unordered lists.

📝
ul + li Semantic replacement for directory-style lists
Replacement
🛠
dir attribute Still valid for ltr/rtl text direction on any element
Valid
<dir> tag 95% legacy rendering

Bottom line: Browsers still render <dir> for old pages, but it is obsolete. Use ul in all new projects.

Conclusion

The <dir> tag is an obsolete directory list element. Use <ul> for file and folder lists. For text direction in Arabic, Hebrew, and other languages, use the dir attribute (ltr, rtl)—not the dir element.

💡 Best Practices

✅ Do

  • Use ul for directory lists
  • Use dir="rtl" for RTL text
  • Nest ul for subfolders
  • Style lists with CSS

❌ Don’t

  • Use <dir> in new projects
  • Confuse dir tag with dir attr
  • Assume obsolete tags are best practice
  • Use compact attribute (also obsolete)

Key Takeaways

Knowledge Unlocked

Six truths every developer should know about <dir>

Bookmark these before you ship — they’ll keep your list markup modern and semantic.

6
Core concepts
🚫 02

Obsolete in HTML5

Removed from the spec—not for new projects.

Status
📝 03

ul Replacement

Use ul with li for directory-style lists.

Modern
🔗 04

dir Attribute

dir="ltr" / rtl sets text direction globally.

Valid
📂 05

Nested ul

Subfolder hierarchies with nested unordered lists.

Pattern
🌐 06

Legacy Rendering

Browsers still render it for backward compatibility only.

Compatibility

❓ Frequently Asked Questions

It was a legacy directory list container for file and folder names with li children. It is obsolete in HTML5.
No. The dir attribute sets text direction (ltr, rtl, auto). The dir element was a separate obsolete list tag.
Use ul with li for directory-style lists. Nest ul elements for subfolders.
No. It is obsolete. Browsers may still render it for old pages, but do not use it in new projects.
Both were legacy list elements. dir was for directory listings; menu was for menus. Both are obsolete—use ul or semantic navigation.

Use Modern List Markup

Practice ul directory lists and the dir attribute in the interactive HTML editor.

Try ul examples →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful