Свойство CSS `border`
Базовая поддержка Широко доступно
Эта функция хорошо зарекомендовала себя и работает на многих устройствах и во многих версиях браузеров. Она доступна во всех браузерах с июля 2015 года.
border — CSS-свойство-сокращение, задающее границу элемента. Оно задаёт значения свойств border-width, border-style и border-color.
Попробуйте
border: solid;
border: dashed red;
border: 1rem solid;
border: thick double #32a1ce;
border: 4mm ridge rgb(211 220 50 / 0.6);
<section class="default-example" id="default-example">
<div class="transition-all" id="example-element">
This is a box with a border around it.
</div>
</section>
#example-element {
background-color: #eeeeee;
color: darkmagenta;
padding: 0.75em;
width: 80%;
height: 100px;
}
Составные свойства
Это свойство является сокращением для следующих свойств CSS:
Синтаксис
/* style */ border: solid; /* width | style */ border: 2px dotted; /* style | color */ border: outset #ff3333; /* width | style | color */ border: medium dashed green; /* Global values */ border: inherit; border: initial; border: revert; border: revert-layer; border: unset;
Значения
Свойство задаётся списком из одного, двух или трёх следующих значений, разделённых пробелами:
-
<line-width> - Задаёт толщину границы. Если значение не указано, используется
medium. См.border-width. -
<line-style> - Задаёт стиль границы. Если значение не указано, используется
none. См.border-style. -
color - Задаёт цвет границы. Если значение не указано, используется
currentColor. См.border-color.
Описание
Сокращённое свойство border задаёт ширину, стиль и цвет всех четырёх сторон границы элемента. Для него указывают одно, два или все три значения свойств-компонентов в любом порядке.
Любые неуказанные подзначения устанавливаются в начальное значение. Чтобы граница отображалась, необходимо задать компонент <line-style>, поскольку по умолчанию для стиля используется значение none.
Важно: свойство border нельзя использовать для задания пользовательского значения border-image; вместо этого оно устанавливает для него начальное значение, то есть none.
Сокращённое свойство border особенно полезно, когда все четыре границы должны быть одинаковыми. Если же они должны отличаться друг от друга, можно использовать развёрнутые свойства border-width, border-style и border-color, которые принимают разные значения для каждой стороны. Кроме того, можно задавать свойства для одной границы за раз с помощью физических (например, border-top) и логических (например, border-block-start) свойств границ.
Границы и контуры
Границы и контуры очень похожи. Однако контуры отличаются от границ следующим:
- Контуры не занимают места, поскольку рисуются за пределами содержимого элемента.
- Согласно спецификации, контуры не обязательно должны быть прямоугольными, хотя обычно они именно такие.
Формальное определение
| Начальное значение | как для каждого из свойств, входящих в сокращение: |
|---|---|
| Применяется к | всем элементам |
| Наследуется | нет |
| Вычисленное значение | как для каждого из свойств, входящих в сокращение: |
| Тип анимации | как для каждого из свойств, входящих в сокращение: |
Формальный синтаксис
border = <line-width> || <line-style> || <color> <line-width> = <length> | thin | medium | thick <line-style> = none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outset <color> = <color-base> | currentColor | <system-color> | <light-dark()> | <deprecated-system-color> <color-base> = <hex-color> | <color-function> | <named-color> | <color-mix()> | transparent <system-color> = AccentColor | AccentColorText | ActiveText | ButtonBorder | ButtonFace | ButtonText | Canvas | CanvasText | Field | FieldText | GrayText | Highlight | HighlightText | LinkText | Mark | MarkText | SelectedItem | SelectedItemText | VisitedText <light-dark()> = light-dark( <color>, <color> ) <deprecated-system-color> = ActiveBorder | ActiveCaption | AppWorkspace | Background | ButtonHighlight | ButtonShadow | CaptionText | InactiveBorder | InactiveCaption | InactiveCaptionText | InfoBackground | InfoText | Menu | MenuText | Scrollbar | ThreeDDarkShadow | ThreeDFace | ThreeDHighlight | ThreeDLightShadow | ThreeDShadow | Window | WindowFrame | WindowText <color-function> = <rgb()> | <rgba()> | <hsl()> | <hsla()> | <hwb()> | <lab()> | <lch()> | <oklab()> | <oklch()> | <color()> <named-color> = aliceblue | antiquewhite | aqua | aquamarine | azure | beige | bisque | black | blanchedalmond | blue | blueviolet | brown | burlywood | cadetblue | chartreuse | chocolate | coral | cornflowerblue | cornsilk | crimson | cyan | darkblue | darkcyan | darkgoldenrod | darkgray | darkgreen | darkgrey | darkkhaki | darkmagenta | darkolivegreen | darkorange | darkorchid | darkred | darksalmon | darkseagreen | darkslateblue | darkslategray | darkslategrey | darkturquoise | darkviolet | deeppink | deepskyblue | dimgray | dimgrey | dodgerblue | firebrick | floralwhite | forestgreen | fuchsia | gainsboro | ghostwhite | gold | goldenrod | gray | green | greenyellow | grey | honeydew | hotpink | indianred | indigo | ivory | khaki | lavender | lavenderblush | lawngreen | lemonchiffon | lightblue | lightcoral | lightcyan | lightgoldenrodyellow | lightgray | lightgreen | lightgrey | lightpink | lightsalmon | lightseagreen | lightskyblue | lightslategray | lightslategrey | lightsteelblue | lightyellow | lime | limegreen | linen | magenta | maroon | mediumaquamarine | mediumblue | mediumorchid | mediumpurple | mediumseagreen | mediumslateblue | mediumspringgreen | mediumturquoise | mediumvioletred | midnightblue | mintcream | mistyrose | moccasin | navajowhite | navy | oldlace | olive | olivedrab | orange | orangered | orchid | palegoldenrod | palegreen | paleturquoise | palevioletred | papayawhip | peachpuff | peru | pink | plum | powderblue | purple | rebeccapurple | red | rosybrown | royalblue | saddlebrown | salmon | sandybrown | seagreen | seashell | sienna | silver | skyblue | slateblue | slategray | slategrey | snow | springgreen | steelblue | tan | teal | thistle | tomato | turquoise | violet | wheat | white | whitesmoke | yellow | yellowgreen <color-mix()> = color-mix( <color-interpolation-method> , [ <color> && <percentage [0,100]>? ]#{2}) <rgb()> = rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? ) | rgb( [ <number> | <percentage> | none ]{3} [ / [ <alpha-value> | none ] ]? ) <rgba()> = rgba( <percentage>#{3} , <alpha-value>? ) | rgba( <number>#{3} , <alpha-value>? ) | rgba( [ <number> | <percentage> | none ]{3} [ / [ <alpha-value> | none ] ]? ) <hsl()> = hsl( <hue>, <percentage>, <percentage>, <alpha-value>? ) | hsl( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? ) <hsla()> = hsla( <hue>, <percentage>, <percentage>, <alpha-value>? ) | hsla( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? ) <hwb()> = hwb( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? ) <lab()> = lab( [<percentage> | <number> | none] [ <percentage> | <number> | none] [ <percentage> | <number> | none] [ / [<alpha-value> | none] ]? ) <lch()> = lch( [<percentage> | <number> | none] [ <percentage> | <number> | none] [ <hue> | none] [ / [<alpha-value> | none] ]? ) <oklab()> = oklab( [ <percentage> | <number> | none] [ <percentage> | <number> | none] [ <percentage> | <number> | none] [ / [<alpha-value> | none] ]? ) <oklch()> = oklch( [ <percentage> | <number> | none] [ <percentage> | <number> | none] [ <hue> | none] [ / [<alpha-value> | none] ]? ) <color()> = color( [ from <color> ]? <colorspace-params> [ / [ <alpha-value> | none ] ]? ) <color-interpolation-method> = in [ <rectangular-color-space> | <polar-color-space> <hue-interpolation-method>? | <custom-color-space> ] <alpha-value> = <number> | <percentage> <hue> = <number> | <angle> <colorspace-params> = [<custom-params> | <predefined-rgb-params> | <xyz-params>] <rectangular-color-space> = srgb | srgb-linear | display-p3 | display-p3-linear | a98-rgb | prophoto-rgb | rec2020 | lab | oklab | xyz | xyz-d50 | xyz-d65 <polar-color-space> = hsl | hwb | lch | oklch <hue-interpolation-method> = [ shorter | longer | increasing | decreasing ] hue <custom-color-space> = <dashed-ident> <custom-params> = <dashed-ident> [ <number> | <percentage> | none ]+ <predefined-rgb-params> = <predefined-rgb> [ <number> | <percentage> | none ]{3} <xyz-params> = <xyz> [ <number> | <percentage> | none ]{3} <predefined-rgb> = srgb | srgb-linear | display-p3 | display-p3-linear | a98-rgb | prophoto-rgb | rec2020 <xyz> = xyz | xyz-d50 | xyz-d65
Примеры
Задание розовой выступающей границы
HTML
<div>I have a border, an outline, and a box shadow! Amazing, isn't it?</div>
CSS
div {
border: 0.5rem outset pink;
outline: 0.5rem solid khaki;
box-shadow: 0 0 0 2rem skyblue;
border-radius: 12px;
font: bold 1rem sans-serif;
margin: 2rem;
padding: 1rem;
outline-offset: 0.5rem;
}
Результат
Спецификации
| Спецификация |
|---|
| Модуль фонов и границ CSS, уровень 3 # propdef-border |
Совместимость с браузерами
| Настольные компьютеры | Мобильные устройства | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome для Android | Firefox для Android | Opera для Android | Safari для iOS | Samsung Internet | WebView для Android | WebView для iOS | |
border |
1 |
12 |
1 |
3.5 |
1 |
18 |
4 |
14 |
1 |
1.0 |
4.4 |
1 |
currentColor |
1 |
12 |
1.5 |
9.5 |
4 |
18 |
4 |
14 |
3.2 |
1.0 |
37 |
3.2 |
dashed |
1 |
12 |
1 |
15 |
1 |
18 |
4 |
14 |
1 |
1.0 |
4.4 |
1 |
dotted |
1 |
12 |
1 |
15 |
1 |
18 |
4 |
14 |
1 |
1.0 |
4.4 |
1 |
double |
1 |
12 |
1 |
15 |
1 |
18 |
4 |
14 |
1 |
1.0 |
4.4 |
1 |
groove |
1 |
12 |
1 |
15 |
1 |
18 |
4 |
14 |
1 |
1.0 |
4.4 |
1 |
hidden |
1 |
12 |
1 |
15 |
1 |
18 |
4 |
14 |
1 |
1.0 |
4.4 |
1 |
inset |
1 |
12 |
1 |
15 |
1 |
18 |
4 |
14 |
1 |
1.0 |
4.4 |
1 |
medium |
1 |
12 |
1 |
15 |
1 |
18 |
4 |
14 |
1 |
1.0 |
4.4 |
1 |
none |
1 |
12 |
1 |
15 |
1 |
18 |
4 |
14 |
1 |
1.0 |
4.4 |
1 |
outset |
1 |
12 |
1 |
15 |
1 |
18 |
4 |
14 |
1 |
1.0 |
4.4 |
1 |
ridge |
1 |
12 |
1 |
15 |
1 |
18 |
4 |
14 |
1 |
1.0 |
4.4 |
1 |
solid |
1 |
12 |
1 |
15 |
1 |
18 |
4 |
14 |
1 |
1.0 |
4.4 |
1 |
thick |
1 |
12 |
1 |
15 |
1 |
18 |
4 |
14 |
1 |
1.0 |
4.4 |
1 |
thin |
1 |
12 |
1 |
15 |
1 |
18 |
4 |
14 |
1 |
1.0 |
4.4 |
1 |
transparent |
1 |
12 |
1 |
15 |
1 |
18 |
4 |
14 |
1 |
1.0 |
4.4 |
1 |
См. также
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/border