HTML compact Attribute

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

Definition and Usage

The compact attribute is a boolean hint that a list should render with reduced spacing. It appeared on <ol>, <ul>, <dl>, and <menu>. Interpretation was always browser-specific.

For new pages, use CSS — for example line-height: 80% (a common stand-in) or tighter margin on list items.

Obsolete.

Do not use compact in new HTML. Authors must not use it. Learn it to read legacy markup; ship CSS for spacing.

HTML Syntax

syntax.html
<ul  compact> … </ul>

Same boolean form on <ol>, <dl>, and <menu>. Presence turns the hint on; no value is required.

Attribute Values

Boolean attribute — only presence matters:

ValueDescriptionTry it
(present)Hint: render the list more compactly (browser-defined)Try it
(absent)Default list spacingTry it
compact="compact"Valid boolean spelling — same as bare compactTry it
CSS replacementPrefer line-height: 80% or item marginsTry it

Live Preview

Compare default spacing, the obsolete compact attribute, and a CSS stand-in. Many browsers ignore the attribute visually.

Prefer the CSS mode for real projects. The attribute is obsolete.

list demo
  • First item
  • Second item
  • Third item
  • Fourth item

compact attribute present (may look unchanged)

HTML Examples

Short study snippets. Use Try It Yourself for a live editor. Prefer example 3 for new work.

Example 1 — compact on ul

Legacy pattern: add the boolean attribute to request tighter spacing.

HTML
<ul compact>
  <li>HTML</li>
  <li>CSS</li>
  <li>JavaScript</li>
</ul>
Try It Yourself

How It Works

  1. Boolean attribute — write compact with no value (or compact="compact").
  2. Hint only — the browser decides whether spacing changes.
  3. List content is unchanged; only presentation was affected historically.
  4. Obsolete today — keep for reading old pages, not for new ones.

Example 2 — ol and dl

The same hint applied to ordered and description lists.

HTML
<ol compact>
  <li>Mix the dry ingredients.</li>
  <li>Add the wet ingredients.</li>
  <li>Bake for 20 minutes.</li>
</ol>

<dl compact>
  <dt>HTML</dt>
  <dd>Markup language for pages.</dd>
  <dt>CSS</dt>
  <dd>Styles for presentation.</dd>
</dl>
Try It Yourself

How It Works

  1. Same attribute on <ol> and <dl> (also valid historically on <menu>).
  2. Meaning of the list stays the same — only a spacing hint.
  3. Browser-specific — do not depend on a visible change.
  4. Replace with CSS when updating legacy templates.

Example 3 — CSS replacement

Recommended approach — no compact attribute.

HTML
<style>
  .tight {
    line-height: 80%;
  }
</style>

<ul class="tight">
  <li>HTML</li>
  <li>CSS</li>
  <li>JavaScript</li>
</ul>
Try It Yourself

How It Works

  1. Class + CSS separates structure from presentation.
  2. line-height: 80% is the stand-in suggested for a compact look.
  3. Predictable across browsers — unlike the old attribute.
  4. Tune further with margin / padding on li when needed.

Edge Cases & Pitfalls

Treat compact as historical — CSS is the reliable way to tighten lists.

obsolete

Not for new HTML

Validators flag it. Remove compact when you touch old templates and replace with CSS.

visual

Often ignored

If your list looks the same with or without compact, that is normal in current browsers.

scope

Lists only

Not a global attribute. Putting it on <div> or <p> is invalid.

a11y

Keep tap targets readable

Very tight line-height can hurt readability. Compact should still stay usable.

dir

Obsolete <dir>

Old docs may show compact on <dir>. Prefer <ul> today.

Browser Support

compact is an obsolete HTML attribute on list elements. Engines may still expose it in the DOM, but visual effect is unreliable.

✓ Obsolete · Do not use

compact

Listed as obsolete for ol, ul, dl, and menu. Prefer CSS line-height or margins for compact lists.

Legacy Compatibility only
Google Chrome Attribute may exist; little/no effect
Obsolete*
Mozilla Firefox Attribute may exist; little/no effect
Obsolete*
Apple Safari Attribute may exist; little/no effect
Obsolete*
Microsoft Edge Attribute may exist; little/no effect
Obsolete*
Opera Attribute may exist; little/no effect
Obsolete*
Samsung Internet Attribute may exist; little/no effect
Obsolete*
Internet Explorer Legacy compact list styling
Legacy*
compact Obsolete (often ignored)

Bottom line: *Do not use in new pages. Migrate list spacing to CSS.

Key Takeaways

  • Role: boolean hint for tighter list spacing.
  • Status: obsolete — study for legacy HTML only.
  • Elements: ol, ul, dl, menu.
  • Replace with: CSS line-height / margin.

One line: learn compact for old lists — ship CSS spacing instead.

Frequently Asked Questions

It is a boolean hint that a list (ol, ul, dl, or menu) should render with reduced spacing. How that looks was always browser-specific.
Obsolete. The HTML Living Standard says authors must not use it. Prefer CSS such as line-height: 80% (MDN’s suggested stand-in) or tighter margins on list items.
Historically ol, ul, dl, and menu (and the obsolete dir element). It is not a global attribute.
It is a boolean attribute: present means “compact”; absent means default spacing. Writing compact="compact" is the same as compact.
Modern browsers often ignore it. That is expected — use CSS for real spacing control.
Use CSS line-height, margin, and padding on the list or its items. Do not rely on the compact attribute in new pages.

Next: content

The meta content attribute that pairs with name or http-equiv.

content 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.

8 people found this page helpful