<hr> <!-- HTML5 無需閉合標籤 -->
<hr /> <!-- XHTML 風格亦可 -->
語意:段落級主題分隔 (Thematic break),非單純視覺線條。螢幕閱讀器會宣告「分隔」。
| 屬性 | 作用 | CSS 替代 |
|---|---|---|
| align | left/center/right | margin-left:auto; margin-right:auto; 等 |
| color | 線條顏色 (IE 專屬) | border-color / background-color |
| noshade | 平面顯示 (無 3D 陰影) | border: 0; height: 1px; background: #ccc; |
| size | 高度 (像素) | height |
| width | 寬度 (像素/百分比) | width / max-width |
hr {
border: 0;
border-top: 1px solid #e0e0e0;
margin: 1.5rem 0;
}
hr {
border: 0;
height: 2px;
background: linear-gradient(90deg, transparent, #1a73e8, transparent);
margin: 1.5rem 0;
}
hr {
border: 0;
height: 12px;
background: url("data:image/svg+xml,") center / 100% 100% no-repeat;
}
hr {
border: 0;
border-top: 1px solid #ddd;
position: relative;
margin: 2rem 0;
}
hr::before {
content: "★";
position: absolute;
top: -0.6em;
left: 50%;
transform: translateX(-50%);
background: white;
padding: 0 0.5em;
color: gold;
}
display: none 隱藏 <hr> (會移除語意),改用 visibility: hidden 或 CSS 讓線條透明<div role="separator" aria-orientation="horizontal"> 或 CSS border-top 於區塊元素/* 虛線分隔 */
hr.dashed { border-top: 1px dashed #ccc; }
/* 點線分隔 */
hr.dotted { border-top: 1px dotted #ccc; }
/* 雙線分隔 */
hr.double { border-top: 3px double #ccc; }
/* 陰影分隔 (無實線) */
hr.shadow { border: 0; height: 0; box-shadow: 0 1px 0 #fff, 0 2px 0 #ddd; margin: 1.5rem 0; }