Live Preview
Modern directory-style list using ul:
- Documents
- Pictures
- Music

By the end of this tutorial, you’ll understand the obsolete <dir> element and the modern replacements you should use instead.
How <dir> listed files and folders with li children.
Why HTML5 removed the dir element from the specification.
Use <ul> with <li> for directory-style lists.
Nested ul elements for subfolder hierarchies.
The global dir attribute for ltr/rtl text—not the tag.
Recognize dir in old HTML and migrate to modern markup.
<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.
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>
<li>Documents</li>
<li>Pictures</li>
<li>Music</li>
</ul>Legacy markup wrapped li items inside dir:
<dir>
<li>Documents</li>
<li>Pictures</li>
<li>Music</li>
</dir><dir> held <li> list items—like ul and menu.compact attribute reduced spacing—use CSS instead.dir element with the dir attribute.dir markup for backward compatibility only.| Feature | Syntax / Rule | Notes |
|---|---|---|
| HTML5 status | Obsolete | Do not use in new code |
| Use instead | ul + li | Semantic list markup |
| dir attribute | dir="ltr" / "rtl" | Separate global attribute |
| Children | li | List items inside dir |
| compact attr | Legacy | Also obsolete; use CSS |
| Related obsolete | menu | Also replaced by ul |
<dir> Element vs dir AttributeThese share a name but serve completely different purposes:
| Name | Type | Purpose |
|---|---|---|
<dir> | Element | Obsolete directory list tag |
dir="" | Attribute | Sets ltr, rtl, or auto text direction |
| On any element | Global | html, p, div, span, etc. |
| Still valid | Attribute only | Use for RTL languages |
The obsolete <dir> element had no useful tag-specific attributes in modern HTML:
compact ObsoleteLegacy boolean attribute for tighter list spacing. Use CSS line-height or margin instead.
<dir compact>class / id GlobalCould be applied historically—prefer ul with CSS classes today.
<ul class="directory-list">dir attribute ValidThe global dir attribute on any element sets text direction—unrelated to this tag.
dir="rtl"Element status ObsoleteThe 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.
Historical <dir> patterns plus modern ul replacements. Legacy examples are for learning only—do not use in new code.
Modern directory-style list using ul:
Historical markup only—do not use in new projects.
<dir>
<li>Documents</li>
<li>Pictures</li>
<li>Music</li>
</dir>Developers once used <dir> for file and folder listings. Today use <ul> with semantic list markup and CSS for styling.
The correct modern approach for directory-style lists.
<ul class="directory-list">
<li>Documents</li>
<li>Pictures</li>
<li>Music</li>
</ul>Use nested ul elements for subfolders—replacing nested dir.
<ul>
<li>File 1</li>
<li>File 2</li>
<li>Folder 1
<ul>
<li>Subfile 1</li>
<li>Subfile 2</li>
</ul>
</li>
</ul>The dir attribute sets text direction—unrelated to the obsolete dir element.
<p dir="ltr">Left-to-right: Hello, welcome.</p>
<p dir="rtl">Right-to-left: مرحبًا بكم.</p>Style modern ul directory lists instead of obsolete dir markup:
list-style Bullets or nonepadding Indent nested foldersline-height Compact spacing::marker Custom list icons/* 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
Use semantic list markup and the correct direction tools:
dir="rtl" on content in Arabic, Hebrew, etc.dir listed files and folders with li children.
One list element handles all unordered lists semantically.
New projects use ul. Browsers still render old pages.
For text direction, use the dir attribute—not the dir tag.
Browsers still render obsolete <dir> for backward compatibility, but the element is not valid HTML5.
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.
HTML5 consolidated list markup—use ul for all unordered lists.
Bottom line: Browsers still render <dir> for old pages, but it is obsolete. Use ul in all new projects.
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.
ul for directory listsdir="rtl" for RTL textul for subfolders<dir> in new projectsdir tag with dir attrcompact attribute (also obsolete)<dir>Bookmark these before you ship — they’ll keep your list markup modern and semantic.
<dir> listed files and folders with li children.
Removed from the spec—not for new projects.
StatusUse ul with li for directory-style lists.
dir="ltr" / rtl sets text direction globally.
Subfolder hierarchies with nested unordered lists.
PatternBrowsers still render it for backward compatibility only.
Compatibilityli children. It is obsolete in HTML5.dir attribute sets text direction (ltr, rtl, auto). The dir element was a separate obsolete list tag.ul with li for directory-style lists. Nest ul elements for subfolders.dir was for directory listings; menu was for menus. Both are obsolete—use ul or semantic navigation.Practice ul directory lists and the dir attribute in the interactive HTML editor.
6 people found this page helpful