大网数据广告活动
Web 标准与前端开发

`<line-width>` CSS type

· 52CE 我爱测

The **`<line-width>`** enumerated value type represents the length or keyword value that defines the width of a line, or the lack of a line. The `<line-width>` keyword values are used in the following longhand and shorthand properties:

The <line-width> enumerated value type represents the length or keyword value that defines the width of a line, or the lack of a line. The <line-width> keyword values are used in the following longhand and shorthand properties:

  • border, border-width
  • border-block, border-block-width
  • border-block-end, border-block-end-width
  • border-block-start, border-block-start-width
  • border-bottom, border-bottom-width
  • border-inline, border-inline-width
  • border-inline-end, border-inline-end-width
  • border-inline-start, border-inline-start-width
  • border-left, border-left-width
  • border-right, border-right-width
  • border-top, border-top-width
  • column-rule, column-rule-width
  • row-rule, row-rule-width
  • rule, rule-width
  • outline, outline-width

Syntax

Values

The <line-width> type is specified using either <length> or a keyword:

  • <length>
    • : A non-negative <length>.
  • hairline
    • : Represents a "just visible" line that is less than or equal to 1px.
  • thin
    • : Same as 1px.
  • medium
    • : Same as 3px.
  • thick
    • : Same as 5px.

Formal syntax

Examples

Defining a line width

This example demonstrates all the <line-width> keyword values, along with a <length> value.

HTML

We include five boxes within a section element.

<section>
  <div data-width="hairline">hairline</div>
  <div data-width="thin">thin</div>
  <div data-width="medium">medium</div>
  <div data-width="thick">thick</div>
  <div data-width="10px">10px</div>
</section>

CSS

We style all the elements to be identical, then set the border-width based on the element's data-width attribute.

section {
  display: flex;
  gap: 10px;
}
div {
  flex: 0 0 15%;
  border-style: solid;
  border-color: purple;
  text-align: center;
}
[data-width="hairline"] {
  border-width: hairline;
}

[data-width="thin"] {
  border-width: thin;
}

[data-width="medium"] {
  border-width: medium;
}

[data-width="thick"] {
  border-width: thick;
}

[data-width="10px"] {
  border-width: 10px;
}
@supports not (border-width: hairline) {
  body::before {
    content: "Your browser does not support the 'hairline' value.";
    color: black;
    background-color: #ffcd33;
    display: block;
    width: 100%;
    text-align: center;
  }
}

Result

Defining a line width

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。