border style property

Browser support:
Sets or retrieves up to three separate border properties, in a shorthand form.
With this property you can customize the borders that appear around HTML elements. You have control over the width, style and color of the border.

border-style: dotted
border-style: dashed
border-style: solid
border-style: double
border-style: inset
border-style: outset
border-style: groove
border-style: ridge
border-style: window-inset

Syntax:

object.border;
You can find the related objects in the Supported by objects section below.
This property is read/write.
CSS page for this property: border

Possible values:

The type of this property is string.
 One of the following values: 
 Any of the following values (use the space character to separate them, each value can be used only once): 
border-color
 One of the following values: 
<color>
transparent
-moz-use-text-color
border-style
 One of the following values: 
dotted
dashed
double
groove
hidden
inset
none
outset
ridge
solid
window-inset
-moz-bg-inset
-moz-bg-outset
-moz-bg-solid
border-width
 One of the following values: 
<border width in non-negative length>
medium
thin
thick
inherit

Description of values:

-moz-bg-inset
The border looks as though it were embedded in the canvas.
-moz-bg-outset
The border looks as though it were coming out of the canvas.
-moz-bg-solid
A solid line is drawn.
-moz-use-text-color
The color of the border should be the same as the text color.
border width in non-negative length
The width of the border in length units. For the supported length units, see the length page.
color
Color of the border. For the supported color values, see the colors page.
dashed
A series of short line segments is drawn.
dotted
A series of dots is drawn.
double
A double line border.
groove
The border looks as if it has been carved into the background.
hidden
Turns the border off.
inherit
Takes the value of this property from the computed style of the parent element.
inset
The border looks as though it were embedded in the canvas.
medium
Default.
none
Default. Border width is null.
outset
The border looks as though it were coming out of the canvas.
ridge
The border looks as if it's protruding out of the background.
solid
A solid line is drawn.
thick
Greater than the medium width.
thin
Less than the medium width.
transparent
Default. Underlying content will shine through.
window-inset
The border looks as though it were embedded in the canvas with an additional single line.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the margin, border and padding properties:
<head>
    <style>
        .outer {
            border: 1px solid #ffffff;
            background-color: #ffb08a;
        }
        .middle {
            margin: 20px;
            padding: 20px;
            border: 10px solid #000000;
            background-color: #ceb379;
        }
        .inner {
            height: 10px;
            border: 1px solid #ffffff;
            background-color: #ffffff;
        }
    </style>
</head>
<body>
    <table cellpadding="0px" cellspacing="10px">
        <tr>
            <td style="background-color: #ffb08a;">&nbsp;</td>
            <td>margin</td>
            <td style="background-color: #000000;">&nbsp;</td>
            <td>border</td>
            <td style="background-color: #ceb379;">&nbsp;</td>
            <td>padding</td>
        </tr>
    </table>
    
    <div class="outer">
        <div class="middle">
            <div class="inner"></div>
        </div>
    </div>
</body>
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the border property in JavaScript:
<head>
    <script type="text/javascript">
        function ChangeBorder () {
            var selectTags = document.getElementsByTagName ("select");
            var selectState = [];
            
            for (i = 0; i < selectTags.length; i++) {
                // Returns the index of the selected option
                whichSelected = selectTags[i].selectedIndex;

                // Returns the text of the selected option
                selectState[i] = selectTags[i].options[whichSelected].text;
            }

            var div = document.getElementById ("myDiv");
            div.style.border = selectState[0] + " " + selectState[1] + " " + selectState[2];
        }

    </script>
</head>
<body>
    <div id="myDiv" style="border: 1px solid blue">Sample division with border</div>

    <select onchange="ChangeBorder ();" size="5">
        <option selected="selected" />1px
        <option />3px
        <option />8px
        <option />15px
        <option />24px
    </select>
    <select onchange="ChangeBorder ();" size="10">
        <option />dotted
        <option />dashed
        <option />double
        <option />groove
        <option />inset
        <option />none
        <option />outset
        <option />ridge
        <option selected="selected" />solid
        <option />window-inset
    </select>
    <select onchange="ChangeBorder ();" size="8">
        <option selected="selected" />blue
        <option />red
        <option />cyan
        <option />white
        <option />green
        <option />yellow
        <option />purple
        <option />black
    </select>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content