---
title: margin-right
slug: Web/CSS/margin-right
tags:
  - CSS
  - CSS Property
  - Reference
  - 'recipe:css-property'
translation_of: Web/CSS/margin-right
---
<div>{{CSSRef}}</div>

<p><strong><code>margin-right</code></strong> は <a href="/ja/docs/CSS">CSS</a> のプロパティで、要素の右側の<a href="/ja/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model">マージン領域</a>を設定します。正の数を指定すると、隣との間が遠くなるように配置され、負の数を指定すると、近くなるように配置します。</p>

<div>{{EmbedInteractiveExample("pages/css/margin-right.html")}}</div>

<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div>

<p>二つの隣り合うボックスの垂直マージンは融合することがあります。これは<a href="/ja/docs/CSS/margin_collapsing"><em>マージンの相殺</em></a>と呼ばれています。</p>

<h2 id="Syntax" name="Syntax">構文</h2>

<pre class="brush:css no-line-numbers notranslate">/* &lt;length&gt; 値 */
margin-right: 20px;  /* 絶対的な寸法 */
margin-right: 1em;   /* 文字の寸法からの相対 */
margin-right: 5%;    /* 直近のブロックコンテナーの幅からの相対 */

/* キーワード値 */
margin-right: auto;

/* グローバル値 */
margin-right: inherit;
margin-right: initial;
margin-right: unset;
</pre>

<p><code>margin-right</code> プロパティは <code>auto</code> キーワード、または <code>&lt;length&gt;</code> や <code>&lt;percentage&gt;</code> で指定されます。正の数、ゼロ、負の数が指定できます。</p>

<h3 id="Values" name="Values">値</h3>

<dl>
 <dt>{{cssxref("&lt;length&gt;")}}</dt>
 <dd>固定値によるマージンの寸法です。</dd>
 <dt>{{cssxref("&lt;percentage&gt;")}}</dt>
 <dd>包含ブロックの <em>width</em> に対するパーセントによるマージンの寸法です。</dd>
 <dt><code>auto</code></dt>
 <dd>右マージンは未使用の水平方向の余白を共有します。これは主に使用されているレイアウトモードによって決定されます。 <code>margin-left</code> と <code>margin-right</code> の両方が <code>auto</code> の場合は、両方に均等に割り当てられます。それ以外の場合は以下の表のとおりです。
 <table class="standard-table">
  <thead>
   <tr>
    <th scope="col">{{cssxref("display")}} の値</th>
    <th scope="col">{{cssxref("float")}} の値</th>
    <th scope="col">{{cssxref("position")}} の値</th>
    <th scope="col"><code>auto</code> の計算値</th>
    <th scope="col">コメント</th>
   </tr>
  </thead>
  <tbody>
   <tr>
    <th><code>inline</code>, <code>inline-block</code>, <code>inline-table</code></th>
    <th><em>任意</em></th>
    <th><code>static</code> または <code>relative</code></th>
    <td><code>0</code></td>
    <td>インラインレイアウトモード</td>
   </tr>
   <tr>
    <th><code>block</code>, <code>inline</code>, <code>inline-block</code>, <code>block</code>, <code>table</code>, <code>inline-table</code>, <code>list-item</code>, <code>table-caption</code></th>
    <th><em>任意</em></th>
    <th><code>static</code> または <code>relative</code></th>
    <td><code>0</code>。ただし <code>margin-left</code> と <code>margin-right</code> が共に <code>auto</code> に設定されていた場合は、親要素の中で中央揃えする値に設定されます。</td>
    <td>ブロックレイアウトモード</td>
   </tr>
   <tr>
    <th><code>block</code>, <code>inline</code>, <code>inline-block</code>, <code>block</code>, <code>table</code>, <code>inline-table</code>, <code>list-item</code>, <code>table-caption</code></th>
    <th><code>left</code> または <code>right</code></th>
    <th><code>static</code> または <code>relative</code></th>
    <td><code>0</code></td>
    <td>ブロックレイアウトモード (フロート要素)</td>
   </tr>
   <tr>
    <th><code>table-*</code> <em>すべて</em>、ただし <code>table-caption</code> <em>を除く</em></th>
    <th><em>任意</em></th>
    <th><em>任意</em></th>
    <td><code>0</code></td>
    <td>内部の <code>table-*</code> 要素にはマージンがありません。代わりに {{ cssxref("border-spacing") }} を使用してください</td>
   </tr>
   <tr>
    <th><code>flex</code>、 <code>inline-flex</code>, <code>table-*</code> <em>以外のすべて</em></th>
    <th><em>任意</em></th>
    <th><em><code>fixed</code></em> または <code>absolute</code></th>
    <td><code>0</code>。ただし <code>margin-left</code> と <code>margin-right</code> が共に <code>auto</code> に設定されていた場合は、ボーダー領域を <code>width</code> の中で中央揃えする値に設定されます(固定されている場合)。</td>
    <td>絶対位置指定配置モード</td>
   </tr>
   <tr>
    <th><code>flex</code>, <code>inline-flex</code></th>
    <th><em>任意</em></th>
    <th><em>任意</em></th>
    <td><code>0</code>。ただし、水平に正の余白がある場合は、 <code>auto</code> を指定したすべてのマージンに均等に割り振られます。</td>
    <td>フレックスボックス配置モード</td>
   </tr>
  </tbody>
 </table>
 </dd>
</dl>

<h2 id="Formal_definition" name="Formal_definition">公式定義</h2>

<p>{{cssinfo}}</p>

<h2 id="Formal_syntax" name="Formal_syntax">形式文法</h2>

{{csssyntax}}

<h2 id="Examples" name="Examples">例</h2>

<h3 id="Setting_right_margin_using_pixels_and_percentages" name="Setting_right_margin_using_pixels_and_percentages">ピクセル数とパーセント値を使用した右マージンの設定</h3>

<pre class="brush: css notranslate">.content { margin-right: 5%; }
.sidebox { margin-right: 10px; }
.logo    { margin-right: -5px; }
</pre>

<h2 id="Specifications" name="Specifications">仕様書</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">仕様書</th>
   <th scope="col">状態</th>
   <th scope="col">備考</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('CSS3 Box', '#the-margin', 'margin-right')}}</td>
   <td>{{Spec2('CSS3 Box')}}</td>
   <td>目立った変更なし。</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS3 Flexbox', '#item-margins', 'margin-right')}}</td>
   <td>{{Spec2('CSS3 Flexbox')}}</td>
   <td>フレックス項目での <code>margin-right</code> の挙動を定義。</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS2.1', 'box.html#margin-properties', 'margin-right')}}</td>
   <td>{{Spec2('CSS2.1')}}</td>
   <td>CSS1 と同様、ただしインライン要素での効果は削除。</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS1', '#margin-right', 'margin-right')}}</td>
   <td>{{Spec2('CSS1')}}</td>
   <td>初回定義</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2>

<p>{{Compat("css.properties.margin-right")}}</p>

<h2 id="See_also" name="See_also">関連情報</h2>

<ul>
 <li>{{cssxref("margin-top")}}, {{cssxref("margin-bottom")}}, {{cssxref("margin-left")}} と {{cssxref("margin")}} 一括指定</li>
 <li>対応付けられる論理的プロパティ: {{cssxref("margin-block-start")}}, {{cssxref("margin-block-end")}}, {{cssxref("margin-inline-start")}}, {{cssxref("margin-inline-end")}} および一括指定の {{cssxref("margin-block")}} と {{cssxref("margin-inline")}}</li>
</ul>