The vspace attribute sets vertical white space in pixels above and below an <img> (and historically <object>). For example, vspace="20" adds 20px on the top and bottom.
Its horizontal twin is hspace. For new pages, use CSS margin instead of either attribute.
Deprecated.
Presentational HTML. MDN: use the CSS margin property (or margin-top / margin-bottom) instead. Keep this page for reading legacy markup.
Still rendered in many browsers.
Support remains for compatibility, but it is not recommended for new projects or modern responsive layouts.
Syntax
HTML Syntax
syntax.html
<img vspace="pixels">
pixels is a non-negative integer (CSS pixels of space on both the top and the bottom).
Change the legacy vspace value and watch the gap above and below the image. Prefer CSS for real projects.
Demo only. New layouts should use CSS margin.
Text + image + text
Line above the image.
Line below the image.
vspace="20" (deprecated demo)
Code
HTML Examples
Short snippets for study. Prefer the CSS example for new work. Use Try It Yourself for a live editor.
Example 1 — Legacy Image vspace
How old pages added top/bottom space around an image.
HTML
<p>Line above the image.</p>
<p>
<img
src="/images/html.png"
alt="HTML logo"
width="64"
height="64"
vspace="20">
</p>
<p>Line below the image with 20px of space on top and bottom.</p>
Both deprecated. Replace with one CSS margin rule, e.g. margin: 8px 16px;.
Migration tip. Search the codebase for vspace= and convert matches to CSS.
Edge Cases & Pitfalls
Treat vspace as history. Modern layout needs CSS, not presentational attributes.
deprecated
Do not use in new code
Validators and style guides flag vspace. Use CSS margins for all new markup.
both sides
Always top and bottom
vspace cannot set only one side. CSS can: set margin-top or margin-bottom alone.
units
Pixels only
The attribute takes an integer pixel count. CSS allows rem, %, and responsive values.
css wins
Stylesheets override clarity
Mixing vspace with CSS margin makes spacing hard to reason about. Pick CSS and remove the attribute.
a11y
Keep alt text
Spacing attributes do not replace a meaningful alt on images.
Compatibility
Browser Support
vspace is a deprecated HTML attribute kept for legacy pages. Prefer CSS margin in modern code.
✓ Deprecated · Legacy support
vspace
Still honored in many browsers for old content, but removed from modern authoring guidance. Do not rely on it for new layouts.
LegacyCompatibility focus
Google ChromeLegacy support
Supported
Mozilla FirefoxLegacy support
Supported
Apple SafariLegacy support
Supported
Microsoft EdgeLegacy support
Supported
OperaLegacy support
Supported
Samsung InternetLegacy support
Supported
Internet ExplorerSupported
Supported
vspaceLegacy / deprecated
Bottom line: Expect old pages to still show vspace gaps, but migrate to CSS margin whenever you touch the markup.
Remember
Key Takeaways
Role: legacy top/bottom pixel spacing on images.
Status: deprecated — do not use in new HTML.
Replace with: CSS margin / margin-block.
Pair:hspace is the horizontal twin — also deprecated.
One line: recognize vspace in old HTML, then space images with CSS margin.
Frequently Asked Questions
It sets vertical white space in pixels above and below elements such as img (and historically object). For example, vspace="20" adds 20px on the top and 20px on the bottom.
Yes. MDN lists vspace as a deprecated presentational attribute. New code should use CSS margin (or margin-top / margin-bottom / margin-block) instead.
It was used mainly on img, and also on older object (and related) embeds. Prefer CSS spacing for all of them today.
vspace adds top and bottom space. hspace adds left and right space. Both are deprecated in favor of CSS margin.
Use margin for equal sides, or margin-top and margin-bottom for control. Example: style="margin-top: 20px; margin-bottom: 20px;" or a stylesheet rule such as margin-block: 20px.
Yes, briefly — you may see it in old pages. Understand it, then migrate spacing to CSS for maintainable layouts.