spacer element
spacer is obsolete and does nothing in any current browser; the gap it was meant to add is gone, so set it with CSS margin or gap.
- Avoid
- Deprecated
- Severity
- DeprecatedFormally obsolete, but inert.
- Basis
- Obsoleted by the specA standard defined it, then removed it.
- Detectable
- YesMatched exactly. Autofixable when the rule carries a fix.
- Matches
spacerElement rule, inside <body>.- Fix
- None — reports only
- Impacts
- Maintainability
- Related
element/center,element/nobr
<spacer type="horizontal" size="40"> asked the browser for a blank gap of a given size. It was a
Netscape extension from the days before CSS, used to push table cells, images and navigation
links apart. It still turns up in old templates, usually between links or at the start of a
paragraph.
Why avoid
It is obsolete. The HTML Standard lists spacer among the elements that “are entirely obsolete,
and must not be used by authors”, with the advice: “Use appropriate elements or CSS instead.”
It also does nothing. The DOM section maps spacer to HTMLUnknownElement, and the rendering
section defines no styles for it. The browser ignores its type, size, width, height and
align attributes, so the space the author wanted is simply missing from the page, and nothing
warns anyone.
It isn’t harmless either, because spacer is not a void element. The spec’s list of void
elements, the ones that never have content, is area, base, br, col, embed, hr, img,
input, link, meta, source, track and wbr. spacer was almost always written without
an end tag, so the parser opens it as a normal element, and everything after it, up to the end of
its parent, becomes its content:
<!-- written -->
<p>One<spacer size="40">Two <b>three</b></p>
<!-- parsed -->
<p>One<spacer size="40">Two <b>three</b></spacer></p>
The dead tag ends up wrapping live text. That changes which element is the parent of that content, so child selectors and scripts that walk the DOM see a structure nobody intended.
Use instead
Delete it and put the space in CSS. For a row of items, use gap on a flex or grid container:
<nav class="toolbar">
<a href="/">Home</a>
<a href="/about">About</a>
</nav>
.toolbar { display: flex; gap: 2.5rem; }
CSS Box Alignment describes the gap properties as specifying “fixed-length gutters between items in the container”. For space next to one element, use a margin on that element:
.lead { margin-block-end: 1.5rem; }
Detectability
Fully detectable by tag name. There is no autofix: an unclosed spacer contains the content that
follows it, so removing the element would delete that content.
Resources
- HTML Standard — Non-conforming features —
spaceris entirely obsolete; use CSS instead. - HTML Standard — Elements in the DOM —
spacermaps toHTMLUnknownElement. - HTML Standard — Void elements —
spaceris not void, so an unclosed one wraps the content after it. - CSS Box Alignment Module Level 3 — gap — fixed-length gutters between items in flex, grid and multi-column containers.
This page is generated from content/rules/element/spacer.md, the same file the linter is built from. Think the rule is wrong, or that browsers moved on? Say so — that is the most useful issue you can file.