HTML vspace Attribute

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

Definition and Usage

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.

HTML Syntax

syntax.html
<img vspace=" pixels">

pixels is a non-negative integer (CSS pixels of space on both the top and the bottom).

Attribute Values

Legacy value form and the modern replacement:

Value / approachDescriptionTry it
integerPixels of space above and below (e.g. 20)Try it
0No extra vertical space from vspaceTry it
CSS marginRecommended replacement for top/bottom spacingTry it
With hspaceOld pages often set both; both are deprecatedTry it

Live Preview

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.

HTML logo

Line below the image.

vspace="20" (deprecated demo)

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>
Try It Yourself

How It Works

  1. vspace is pixels. 20 means 20px above and 20px below.
  2. Applies to the image. Space sits between the image box and nearby content.
  3. Equal on both sides. You cannot set only top or only bottom with this attribute.
  4. Study only. Do not copy this pattern into new production pages.

Example 2 — Modern CSS Replacement

Same idea with margin — the approach MDN recommends.

HTML
<p>Line above the image.</p>
<p>
  <img
    src="/images/html.png"
    alt="HTML logo"
    width="64"
    height="64"
    style="margin: 20px 0;">
</p>
<p>Same vertical spacing using CSS margin instead of vspace.</p>
Try It Yourself

How It Works

  1. Replace vspace. Vertical gaps become margin-top / margin-bottom (or shorthand).
  2. More control. CSS can set unequal sides, rem units, or responsive rules.
  3. Prefer a stylesheet. Move spacing out of inline styles for real sites.
  4. Logical properties. margin-block maps to top/bottom in horizontal writing modes.

Example 3 — vspace with hspace

Legacy pages often set both axes of presentational spacing.

HTML
<img
  src="/images/html.png"
  alt="HTML logo"
  width="64"
  height="64"
  vspace="8"
  hspace="16">
Try It Yourself

How It Works

  1. vspace="8". 8px above and 8px below.
  2. hspace="16". 16px left and 16px right.
  3. Both deprecated. Replace with one CSS margin rule, e.g. margin: 8px 16px;.
  4. 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.

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.

Legacy Compatibility focus
Google Chrome Legacy support
Supported
Mozilla Firefox Legacy support
Supported
Apple Safari Legacy support
Supported
Microsoft Edge Legacy support
Supported
Opera Legacy support
Supported
Samsung Internet Legacy support
Supported
Internet Explorer Supported
Supported
vspace Legacy / deprecated

Bottom line: Expect old pages to still show vspace gaps, but migrate to CSS margin whenever you touch the markup.

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.

Next: width

Set intrinsic or layout width on elements such as images and tables.

width 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