--- title: border-width slug: Web/CSS/border-width tags: - CSS - CSS プロパティ - CSS 背景と境界 - Reference - border - border-width - リファレンス translation_of: Web/CSS/border-width ---
CSS の border-width プロパティは、要素の境界線の四辺すべての線の幅を設定する一括指定プロパティです。
それぞれの辺は個別に、 {{cssxref("border-top-width")}}, {{cssxref("border-right-width")}}, {{cssxref("border-bottom-width")}}, {{cssxref("border-left-width")}} や、書字方向による指定を利用して {{cssxref("border-block-start-width")}}, {{cssxref("border-block-end-width")}}, {{cssxref("border-inline-start-width")}}, {{cssxref("border-inline-end-width")}} で設定することができます。
/* キーワード値 */ border-width: thin; border-width: medium; border-width: thick; /* <length> 値 */ border-width: 4px; border-width: 1.2rem; /* 上下 | 左右 */ border-width: 2px 1.5em; /* 上 | 左右 | 下 */ border-width: 1px 2em 1.5cm; /* 上 | 右 | 下 | 左 */ border-width: 1px 2em 0 4rem; /* グローバルキーワード */ border-width: inherit; border-width: initial; border-width: unset;
border-width プロパティは一つ、二つ、三つ、四つの値を使って指定することができます。
<line-width>thin |
|
細い境界線 |
medium |
|
中くらいの境界線 |
thick |
|
太い境界線 |
メモ: 仕様書ではそれぞれのキーワードで示される正確な太さを定義していないため、何れか一つを使用した場合の詳細な結果は、実装に依存します。とは言っても、常に thin ≤ medium ≤ thick というパターンに従い、値は同じ文書の中では一貫しています。
<p id="sval">
one value: 6px wide border on all 4 sides</p>
<p id="bival">
two different values: 2px wide top and bottom border, 10px wide right and left border</p>
<p id="treval">
three different values: 0.3em top, 9px bottom, and zero width right and left</p>
<p id="fourval">
four different values: "thin" top, "medium" right, "thick" bottom, and 1em left</p>
#sval {
border: ridge #ccc;
border-width: 6px;
}
#bival {
border: solid red;
border-width: 2px 10px;
}
#treval {
border: dotted orange;
border-width: 0.3em 0 9px;
}
#fourval {
border: solid lightgreen;
border-width: thin medium thick 1em;
}
p {
width: auto;
margin: 0.25em;
padding: 0.25em;
}
{{ EmbedLiveSample('A_mix_of_values_and_lengths', 320, 320) }}
| 仕様書 | 状態 | 備考 |
|---|---|---|
| {{SpecName('CSS3 Backgrounds', '#the-border-width', 'border-width')}} | {{Spec2('CSS3 Backgrounds')}} | 直接は変更なし。 CSS の {{cssxref("<length>")}} データ型拡張がこのプロパティに影響。 |
| {{SpecName('CSS2.1', 'box.html#border-width-properties', 'border-width')}} | {{Spec2('CSS2.1')}} | 値の意味が文書内で一定でなければならないという制限を追加。 |
| {{SpecName('CSS1', '#border-width', 'border-width')}} | {{Spec2('CSS1')}} | 初回定義 |
{{cssinfo}}
{{Compat("css.properties.border-width")}}