--- title: margin-top slug: Web/CSS/margin-top tags: - CSS - CSS Property - Reference - 'recipe:css-property' translation_of: Web/CSS/margin-top ---
margin-top は CSS のプロパティで、要素の上側のマージン領域を設定します。正の数を指定すると、隣との間が遠くなるように配置され、負の数を指定すると、近くなるように配置します。
このプロパティは、置換要ではないインライン要素、例えば {{HTMLElement("span")}} や {{HTMLElement("code")}} には効果がありません。
/* <length> 値 */ margin-top: 10px; /* 絶対的な寸法 */ margin-top: 1em; /* 文字の寸法からの相対 */ margin-top: 5%; /* 直近のブロックコンテナーの幅からの相対 */ /* キーワード値 */ margin-top: auto; /* グローバル値 */ margin-top: inherit; margin-top: initial; margin-top: unset;
margin-top プロパティは auto キーワード、または <length> や <percentage> で指定されます。正の数、ゼロ、負の数が指定できます。
auto{{cssinfo}}
.content { margin-top: 5%; }
.sidebox { margin-top: 10px; }
.logo { margin-top: -5px; }
#footer { margin-top: 1em; }
| 仕様書 | 状態 | 備考 |
|---|---|---|
| {{SpecName('CSS3 Box', '#the-margin', 'margin-top')}} | {{Spec2('CSS3 Box')}} | 目立った変更なし。 |
| {{SpecName('CSS2.1', 'box.html#margin-properties', 'margin-top')}} | {{Spec2('CSS2.1')}} | ただしインライン要素での効果を削除。 |
| {{SpecName('CSS1', '#margin-top', 'margin-top')}} | {{Spec2('CSS1')}} | 初回定義 |
{{Compat("css.properties.margin-top")}}