HTML <center> 标签是一个块级元素,可以在其中包含块级元素和内联内容。在 <center> 元素之间编写的内容将显示在页面的中间。

HTML4 中已经弃用了 <center> 标签,在 HTML5 中被废弃了。

注意:<center> 标签现在已经被弃用,所以你可以使用 CSS 属性 text-align: center; 来实现相同的效果。

语法

<center>Add Content Here....</center>

以下是 <center> 标签的一些规范:

属性
显示内联
开始标签/结束标签都有开始和结束标签
用法文本

示例

使用 <center> 标签

<!DOCTYPE html>
<html>
<head>
  <title>Center tag</title>
</head>
<body>
  <h2>Example of center tag</h2>
  <center>This content is displayed in the middle of the page, but try to use CSS property to align the content as this tag is deprecated now.</center>
</body>
</html>

使用 CSS

<!DOCTYPE html>
<html>
<head>
  <title>Center tag</title>
  <style>
    h2 {
      text-align: center;
    }
  </style>
</head>
<body>
  <h2>Example of center tag</h2>
  <p>This content is aligned centered using CSS property.</p>
</body>
</html>

输出
uTools_1686112702061.png

属性

HTML <center> 标签在 HTML 中不包含任何特定的属性,但支持全局属性(只要 <center> 标签尚未完全删除)。

支持的浏览器

元素chrome browser Chromeie browser IEfirefox browser Firefoxopera browser Operasafari browser Safari
<center>

标签: html, HTML教程, HTML技术, HTML学习, HTML学习教程, HTML下载, HTML语言, HTML开发, HTML入门教程, HTML进阶教程, HTML高级教程, HTML面试题, HTML笔试题, HTML编程思想