mozilla

Revision 573717 of border-width

  • Revision slug: Web/CSS/border-width
  • Revision title: border-width
  • Revision id: 573717
  • Created:
  • Creator: J-Mackerel
  • Is current revision? No
  • Comment Update compat table. convert demo to live sample format.

Revision Content

{{CSSRef}}

Summary

The border-width CSS property sets the width of the border of a box. Using the shorthand property {{cssxref("border")}} is often more convenient.

{{cssbox("border-width")}}

Syntax

Formal syntax: {{csssyntax("border-width")}}
border-width: width                  /* One-value syntax */
border-width: horizontal vertical    /* Two-value syntax */
border-width: top vertical bottom    /* Three-value syntax */
border-width: top right bottom left  /* Four-value syntax */

border-width: inherit

Values

<br-width>
Is either a non-negative explicit {{xref_csslength}} value or a keyword denoting the thickness of the bottom border. The keyword must be one of the following values:
thin
 
A thin border
medium
 
A medium border
thick
 
A thick border
The specification doesn't precisely define the thickness of each of the keywords, which is therefore implementation specific. Nevertheless, it requests that the thickness does follow the thin ≤ medium ≤ thick inequality and that the values are constant on a single document.

inherit

Is a keyword indicating that all four values are inherited from their parent's element calculated value.

Examples

A mix of values and lengths

HTML

<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 right</p>

CSS

#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;
}

Result

{{ EmbedLiveSample('A_mix_of_values_and_lengths', 300, 180) }}

Specifications

Specification Status Comment
{{SpecName('CSS3 Backgrounds', '#the-border-width', 'border-width')}} {{Spec2('CSS3 Backgrounds')}} No direct change, the {{xref_csslength}} CSS data type extension has an effect on this property.
{{SpecName('CSS2.1', 'box.html#border-width-properties', 'border-width')}} {{Spec2('CSS2.1')}} Added the constraint that values' meaning must be constant inside a document.
{{SpecName('CSS1', '#border-width', 'border-width')}} {{Spec2('CSS1')}}  

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 {{CompatGeckoDesktop("1.0")}} 4.0 3.5 1.0 (85)
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 2.0 {{CompatGeckoMobile("1.9.2")}} 6.0 11 3.0

See also

  • The border-related shorthand properties: {{Cssxref("border")}}, {{Cssxref("border-style")}}, {{Cssxref("border-color")}}
  • The border-width-related properties: {{Cssxref("border-bottom-width")}}, {{Cssxref("border-left-width")}}, {{Cssxref("border-right-width")}}, {{Cssxref("border-top-width")}}

Revision Source

<div>
 {{CSSRef}}</div>
<h2 id="Summary">Summary</h2>
<p>The <code>border-width</code> CSS property sets the width of the border of a box. Using the shorthand property {{cssxref("border")}} is often more convenient.</p>
<p>{{cssbox("border-width")}}</p>
<h2 id="Syntax">Syntax</h2>
<pre class="twopartsyntaxbox">
<a href="/en-US/docs/CSS/Value_definition_syntax" title="CSS/Value_definition_syntax">Formal syntax</a>: {{csssyntax("border-width")}}
</pre>
<pre>
border-width: <em>width</em> <em>                 /* One-value syntax */</em>
border-width: <em>horizontal</em> <em>vertical</em> <em>   /* Two-value syntax */</em>
border-width: <em>top</em> <em>vertical</em> <em>bottom </em><em>   /* Three-value syntax */</em>
border-width: <em>top</em> <em>right</em> <em>bottom</em> <em>left </em><em> /* Four-value syntax */</em>

border-width: inherit
</pre>
<h3 id="Values">Values</h3>
<dl>
 <dt>
  <code>&lt;br-width&gt;</code></dt>
 <dd>
  Is either a non-negative explicit {{xref_csslength}} value or a keyword denoting the thickness of the bottom border. The keyword must be one of the following values:
  <table class="standard-table">
   <tbody>
    <tr>
     <td style="vertical-align: middle;"><code>thin</code></td>
     <td style="vertical-align: middle;">
      <div style="margin:0.5em; width:3em; height:3em; border-style:solid; border-width:thin; background-color:palegreen;">
       &nbsp;</div>
     </td>
     <td style="vertical-align: middle;">A thin border</td>
    </tr>
    <tr>
     <td style="vertical-align: middle;"><code>medium</code></td>
     <td style="vertical-align: middle;">
      <div style="margin:0.5em; width:3em; height:3em; border-style:solid; border-width:medium; background-color:palegreen;">
       &nbsp;</div>
     </td>
     <td style="vertical-align: middle;">A medium border</td>
    </tr>
    <tr>
     <td style="vertical-align: middle;"><code>thick</code></td>
     <td style="vertical-align: middle;">
      <div style="margin:0.5em; width:3em; height:3em; border-style:solid; border-width:thick; background-color:palegreen;">
       &nbsp;</div>
     </td>
     <td style="vertical-align: middle;">A thick border</td>
    </tr>
   </tbody>
  </table>
  The specification doesn't precisely define the thickness of each of the keywords, which is therefore implementation specific. Nevertheless, it requests that the thickness does follow the <code>thin ≤ medium ≤ thick</code> inequality and that the values are constant on a single document.</dd>
</dl>
<p><code>inherit</code></p>
<dl>
 <dd>
  Is a keyword indicating that all four values are inherited from their parent's element calculated value.</dd>
</dl>
<h2 id="Examples">Examples</h2>
<h3 name="A_mix_of_values_and_lengths">A mix of values and lengths</h3>
<h4>HTML</h4>
<pre class="brush: html">
&lt;p id="sval"&gt;
&nbsp;   one value: 6px wide border on all 4 sides&lt;/p&gt;
&lt;p id="bival"&gt;
&nbsp;   two different values: 2px wide top and bottom border, 10px wide right and left border&lt;/p&gt;
&lt;p id="treval"&gt;
&nbsp;   three different values: 0.3em top, 9px bottom, and zero width right and left&lt;/p&gt;
&lt;p id="fourval"&gt;
&nbsp;   four different values: "thin" top, "medium" right, "thick" bottom, and 1em right&lt;/p&gt;</pre>
<h4>CSS</h4>
<pre class="brush: css">
#sval {
&nbsp;   border: ridge #ccc;
&nbsp;   border-width: 6px;
}
#bival {
&nbsp;   border: solid red;
&nbsp;   border-width: 2px 10px;
}
#treval {
&nbsp;   border: dotted orange;
&nbsp;   border-width: 0.3em 0 9px;
}
#fourval {
&nbsp;   border: solid lightgreen;
&nbsp;   border-width: thin medium thick 1em;
}
p {
&nbsp;   width: auto;
&nbsp;   margin: 0.25em;
&nbsp;   padding: 0.25em;
}</pre>
<h4>Result</h4>
<p>{{ EmbedLiveSample('A_mix_of_values_and_lengths', 300, 180) }}</p>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('CSS3 Backgrounds', '#the-border-width', 'border-width')}}</td>
   <td>{{Spec2('CSS3 Backgrounds')}}</td>
   <td>No direct change, the {{xref_csslength}} CSS data type extension has an effect on this property.</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS2.1', 'box.html#border-width-properties', 'border-width')}}</td>
   <td>{{Spec2('CSS2.1')}}</td>
   <td>Added the constraint that values' meaning must be constant inside a document.</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS1', '#border-width', 'border-width')}}</td>
   <td>{{Spec2('CSS1')}}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>
 {{CompatibilityTable}}</div>
<div id="compat-desktop">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Chrome</th>
    <th>Firefox (Gecko)</th>
    <th>Internet Explorer</th>
    <th>Opera</th>
    <th>Safari</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>1.0</td>
    <td>{{CompatGeckoDesktop("1.0")}}</td>
    <td>4.0</td>
    <td>3.5</td>
    <td>1.0 (85)</td>
   </tr>
  </tbody>
 </table>
</div>
<div id="compat-mobile">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Android</th>
    <th>Firefox Mobile (Gecko)</th>
    <th>IE Phone</th>
    <th>Opera Mobile</th>
    <th>Safari Mobile</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>2.0</td>
    <td>{{CompatGeckoMobile("1.9.2")}}</td>
    <td>6.0</td>
    <td>11</td>
    <td>3.0</td>
   </tr>
  </tbody>
 </table>
</div>
<h2 id="See_also">See also</h2>
<ul>
 <li>The border-related shorthand properties: {{Cssxref("border")}}, {{Cssxref("border-style")}}, {{Cssxref("border-color")}}</li>
 <li>The border-width-related properties: {{Cssxref("border-bottom-width")}}, {{Cssxref("border-left-width")}}, {{Cssxref("border-right-width")}}, {{Cssxref("border-top-width")}}</li>
</ul>
Revert to this revision