HTML <center> 置中

<center> 標籤 (tag) 用來將 <center> 裡面的內容水平置中。

舉個例子:

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

顯示結果:

This text will be centered.

So will this paragraph.

⚠️ 這是過時的標籤

<center> 標籤早在 HTML 4.01 就被標記為不建議使用(Deprecated),在現代的 HTML5 標準中已正式被移除。

為什麼不應該再使用它?

  • 結構與樣式混雜:HTML 應該只負責語意(內容),而置中屬於樣式設計。
  • 維護困難:過度使用會讓 HTML 變得難以管理。

現代替代方案: 你應該改成使用 CSS 來處理水平與垂直置中:

  • 使用 text-align: center; 處理內聯元素 (inline) 的置中。
  • 使用 Flexbox (display: flex; justify-content: center;)。
  • 使用 CSS Grid (display: grid; place-items: center;)。