HTML <dir> Tag

Beginner
5 min read
Updated: Oct 2026
4 examples
Live preview

Definition and Usage

The <dir> (directory) element was a container for a list of files or folders, with <li> children. Early HTML used it before unordered lists became the standard pattern.

Do not use it in new pages. Use <ul> for lists of any kind, including file listings. Nested <ul> elements cover folder trees.

Deprecated · Obsolete.

Present in early HTML, deprecated in HTML 4, and removed from the living HTML standard. Avoid in every new project.

Not the dir attribute.

The global dir attribute sets text direction (ltr, rtl, auto). It is valid HTML and unrelated to this obsolete list tag.

HTML Syntax

syntax.html
<dir> <li>…</li></dir>

Historical form only. Both tags wrapped <li> items, much like <ul>. Prefer this modern equivalent:

prefer.html
<ul>
  <li>Documents</li>
  <li>Pictures</li>
  <li>Music</li>
</ul>

Attributes

Besides globals, legacy markup sometimes used compact. Do not use it in new work.

AttributeDescriptionTry it
compactDeprecated · Non-standard. Boolean hint for tighter list spacing; browsers differed. Use CSS line-height insteadTry it

Global Attributes

The <dir> tag also supports the Global Attributes in HTML.

Live Preview

Compare legacy <dir> rendering with the modern <ul> replacement.

Study-only preview. Always ship <ul> in real pages.

List
  • Documents
  • Pictures
  • Music
  • Using obsolete <dir> — for learning only.

    HTML Examples

    Short, copy-ready snippets. Use Try It Yourself for a live editor.

    Example 1 — Legacy Directory List

    Historical markup only. Recognize it in old pages; do not copy it into new sites.

    HTML
    <dir>
      <li>Documents</li>
      <li>Pictures</li>
      <li>Music</li>
    </dir>
    Try It Yourself

    How It Works

    1. Open <dir>. This was the directory list container.
    2. Add <li> children for each file or folder name.
    3. Close the tag. Engines often style it like <ul>.
    4. Do not ship this. The living HTML standard marks <dir> as obsolete.

    Example 2 — Replace with <ul>

    Same list, valid HTML5. This is the markup you should write today.

    HTML
    <ul>
      <li>Documents</li>
      <li>Pictures</li>
      <li>Music</li>
    </ul>
    Try It Yourself

    How It Works

    1. Swap the wrapper from <dir> to <ul>.
    2. Keep the same <li> items for each entry.
    3. Get a semantic unordered list that validators and assistive tech understand.
    4. Style with CSS if you need tighter spacing (instead of obsolete compact).

    Example 3 — Nested Folder Tree

    Nest <ul> inside an <li> for subfolders.

    HTML
    <ul>
      <li>readme.txt</li>
      <li>notes.md</li>
      <li>src
        <ul>
          <li>app.js</li>
          <li>styles.css</li>
        </ul>
      </li>
    </ul>
    Try It Yourself

    How It Works

    1. Start a parent <ul> for the top-level entries.
    2. Put a nested <ul> inside a folder <li> for children.
    3. Keep structure in HTML so the hierarchy is clear without icons or scripts.
    4. Avoid nesting <dir> — migrate whole trees to <ul>.

    Example 4 — The Valid dir Attribute

    Text direction uses the global attribute — not the obsolete list element.

    HTML
    <p dir="ltr">Hello from CodeToFun.</p>
    <p dir="rtl">مرحبا بكم في كود تو فن.</p>
    Try It Yourself

    How It Works

    1. Add dir on any element (often <html> or a paragraph).
    2. Use ltr or rtl for left-to-right or right-to-left text (or auto).
    3. Leave list markup to <ul> — direction and lists are separate concerns.
    4. Learn more on the dir attribute page.

    Edge Cases & Pitfalls

    Most mistakes mix up the tag with the attribute, or copy legacy lists into new pages.

    naming

    Element ≠ attribute

    <dir> was a list. The global dir attribute only controls text direction.

    obsolete

    Still rendering ≠ allowed

    Browsers may paint old <dir> for compatibility. Validators and the HTML standard still reject it for authors.

    compact

    Skip compact

    Deprecated and non-standard. Tighten lists with CSS (line-height, margin) on <ul>.

    siblings

    Related legacy lists

    Old <menu> usage was also list-like. Prefer <ul> or semantic <nav> for navigation.

    a11y

    Use real lists

    Screen readers announce proper <ul>/<ol> structure. Stick to those instead of reinventing lists with divs or obsolete tags.

    Browser Support

    Engines may still render <dir> for old pages, but authors must not use it. Prefer <ul> everywhere.

    ✓ Deprecated · Obsolete

    <dir>

    Legacy compatibility only. Chrome, Firefox, Safari, Edge, and Opera may display dir like a list, but the element is removed from the HTML living standard. Always migrate to ul.

    N/A Do not use in new HTML
    Google Chrome Legacy render
    Do not use
    Mozilla Firefox Legacy render
    Do not use
    Apple Safari Legacy render
    Do not use
    Microsoft Edge Legacy render
    Do not use
    Opera Legacy render
    Do not use
    Samsung Internet Legacy render
    Do not use
    Internet Explorer Legacy render
    Do not use
    <dir> Obsolete (use &lt;ul&gt;)

    Bottom line: Recognize <dir> in old markup, then replace it with <ul>. Never add dir to new documents.

    Key Takeaways

    • Role: <dir> was a directory list with <li> children — now obsolete.
    • Replace: use <ul> (and nested <ul>) for file and folder lists.
    • Name clash: the global dir attribute is for text direction, not lists.
    • compact: deprecated/non-standard — control spacing with CSS.

    One line: never write <dir>; write <ul> for directory-style lists.

    Default CSS Settings

    For compatibility, user agents typically style dir like an unordered list:

    default.css
    dir {
      display: block;
      list-style-type: disc;
      margin-block: 1em;
      margin-inline: 0;
      padding-inline-start: 40px;
    }

    Prefer styling ul the same way. Historical compact was roughly like reducing line-height (often cited around 80%) — use modern CSS units instead.

    Frequently Asked Questions

    The dir element was a legacy container for a directory of files or folders, with li children. It is obsolete — use ul for lists, including file lists.
    No. The dir attribute is a global attribute that sets text direction (ltr, rtl, or auto). The dir element was a separate obsolete list tag.
    No. It was deprecated in HTML 4 and removed from the living HTML standard. Do not use it in new projects.
    Use ul with li for directory-style lists. Nest ul elements for folders and subfolders. Style spacing with CSS such as line-height instead of compact.
    compact was a non-standard Boolean hint for tighter spacing. Support was inconsistent. Never use it — control list spacing with CSS.
    Engines keep limited backward compatibility so old pages do not break. Rendering support does not mean the element is allowed in modern HTML.

    Next: div

    Learn the generic flow container used for layout grouping.

    div tutorial →

    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.

    12 people found this page helpful