HTML rightmargin Attribute

The obsolete HTML rightmargin attribute was historically used on the <body> element to control the amount of space between the document content and the right edge of the browser window.

Historical Syntax

The rightmargin attribute was placed on the <body> element and typically used a numeric value representing the requested right margin in pixels.

<body rightmargin="40">

Supporting browsers used the value to leave space between the document content and the right side of the browser window.

Historical Elements

The rightmargin attribute was associated with the <body> element.

Element Historical Purpose
<body> Controlled the amount of space between document content and the right edge of the browser window.

Historical Use

Older webpages sometimes used margin attributes directly on the <body> element to control spacing around the document. The rightmargin attribute specifically controlled spacing along the right side.

<body rightmargin="40">
  <h1>Example Page</h1>
  <p>This page has additional space along its right side.</p>
</body>

The attribute was commonly used with other browser-specific body margin attributes such as leftmargin, topmargin, and bottommargin to control spacing on multiple sides of a page.

Why It Became Obsolete

The rightmargin attribute controlled visual presentation directly through HTML and was not part of standard modern HTML. CSS provides dedicated properties for controlling margins and padding with much greater flexibility.

Using CSS also allows page spacing to change for different screen sizes and layouts without changing the document's HTML structure.

Modern Alternative

Use the CSS margin-right property when an element needs space outside its right edge. For page layouts, CSS padding-right is often more appropriate when the goal is to keep content away from the right edge of its container.

Historical HTML

<body rightmargin="40">
  ...
</body>

Modern HTML

<body>
  <div class="page-content">
    Page content
  </div>
</body>

Modern CSS

.page-content {
  padding-right: 40px;
}

Using padding on a page container creates space inside the container between its content and right edge. If spacing outside an element is required instead, use margin-right.

Play in Editor

Learn More About CSS Spacing

The CSS tutorials explain how margins, padding, and the box model control spacing around elements:

  • CSS Margins - Control space outside an element's border.
  • CSS Padding - Control space between an element's content and border.
  • CSS Box Model - Learn how content, padding, borders, and margins work together.

Legacy Browser Support

The rightmargin attribute was a browser-specific presentational feature supported by some older browsers rather than a standard HTML attribute.

Modern webpages should not rely on rightmargin, even if a browser continues to recognize legacy markup. Use CSS margins or padding for page spacing.

For additional information about historical browser compatibility, visit Can I Use? . Search for the HTML element or attribute you want to check. Search results can include related HTML features, element attributes, APIs, and other technologies, so select the result that most closely matches the legacy feature you are researching.

Other obsolete or non-standard attributes historically used to control spacing include:

  • leftmargin - Historically controlled spacing along the left side of a document.
  • topmargin - Historically controlled spacing along the top of a document.
  • bottommargin - Historically controlled spacing along the bottom of a document.
  • hspace - Historically added horizontal space around certain elements.
  • vspace - Historically added vertical space around certain elements.

Specifications

The rightmargin attribute was a browser-specific presentational feature rather than a standard modern HTML attribute. It should not be used in current webpages. Use CSS margin or padding properties to control spacing instead.