<center>: 居中文字元素

已棄用:此特性不再推薦。雖然某些瀏覽器可能仍然支援它,但它可能已經從相關的網路標準中刪除,可能正在刪除過程中,或者可能僅為相容性目的而保留。請避免使用它,如果可能,請更新現有程式碼;請參閱本頁底部的相容性表格以指導您的決策。請注意,此特性可能隨時停止工作。

<center> HTML 元素是一個 塊級元素,它會將其塊級或內聯內容在容器內水平居中。容器通常是 <body> 元素,但並非必須。

此標籤在 HTML 4 (和 XHTML 1) 中已棄用,推薦使用 CSStext-align 屬性,該屬性可應用於 <div> 元素或單獨的 <p> 元素。要居中塊級元素,請使用其他 CSS 屬性,如 margin-leftmargin-right,並將它們設定為 auto (或將 margin 設定為 0 auto)。

DOM 介面

此元素實現了 HTMLElement 介面。

示例 1

html
<center>
  This text will be centered.
  <p>So will this paragraph.</p>
</center>

結果

示例 2 (CSS 替代方案)

html
<div class="center">
  This text will be centered.
  <p>So will this paragraph.</p>
</div>
css
.center {
  text-align: center;
}

結果

示例 3 (CSS 替代方案)

html
<p class="center">
  This line will be centered.<br />
  And so will this line.
</p>
css
.center {
  text-align: center;
}

結果

注意:text-align: center 應用於 <div><p> 元素會居中這些元素的內容,而不會改變它們的整體尺寸。

規範

規範
HTML
# center

瀏覽器相容性

另見