<center>:中央對齊文字元素

已棄用: 不推薦使用此功能。雖可能有一些瀏覽器仍然支援它,但也許已自相關的網頁標準中移除、正準備移除、或僅為了維持相容性而保留。避免使用此功能,盡可能更新現有程式;請參考頁面底部的相容性表格來下決定。請注意:本功能可能隨時停止運作。

<center> HTML 元素是一個區塊級元素,它將其區塊級或內聯內容在其包含元素中水平居中顯示。通常,容器是 <body>,但不是必需的。

在 HTML 4(和 XHTML 1)中,此標籤已被棄用,取而代之的是 CSStext-align (en-US) 屬性,可以應用於 <div> 元素或個別的 <p>。要將區塊居中,請使用其他 CSS 屬性,如 margin-left (en-US)margin-right (en-US),並將它們設置為 auto(或將 margin (en-US) 設置為 0 auto)。

DOM 介面

此元素實現了 HTMLElement (en-US) 介面。

範例 1

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

結果

範例 2(CSS 替代方案)

html
<div style="text-align:center">
  This text will be centered.
  <p>So will this paragraph.</p>
</div>

結果

範例 3(CSS 替代方案)

html
<p style="text-align:center">
  This line will be centered.<br />
  And so will this line.
</p>

結果

備註:text-align (en-US):center 應用於 <div><p> 元素會將這些元素的內容置中,同時保持它們的整體尺寸不變。

規範

Specification
HTML Standard
# center

瀏覽器相容性

BCD tables only load in the browser

參見