The HTML tag <center>
is used to center-align the content within a block-level element. It was widely used in the early days of the web, but has since been deprecated in HTML5 in favor of using CSS to control layout and alignment.
The <center>
tag is a block-level element that can be used to center-align any content within it. This can include text, images, tables, and other HTML elements. When used, the content within the <center>
tag will be horizontally centered within the parent element.
It is important to note that the <center>
tag has been deprecated in HTML5, which means that it is no longer recommended for use. Instead, developers are encouraged to use CSS to control layout and alignment. This is because CSS provides more flexibility and control over the appearance of a web page, and separates the presentation of the content from the structure of the HTML.
Here are some examples of how the <center>
tag can be used:
To center-align text within a block-level element, simply wrap the text in a <center>
tag:
<div> <center> <h1>Welcome to my website!</h1> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> </center> </div>
This will center-align the heading and paragraph within the <div>
element.
To center-align an image within a block-level element, use the <center>
tag with the <img>
tag:
<div> <center> <img src="image.jpg" alt="My Image"> </center> </div>
This will center-align the image within the <div>
element.
To center-align a table within a block-level element, use the <center>
tag with the <table>
tag:
<div> <center> <table> <tr> <th>Header 1</th> <th>Header 2</th> </tr> <tr> <td>Row 1, Column 1</td> <td>Row 1, Column 2</td> </tr> <tr> <td>Row 2, Column 1</td> <td>Row 2, Column 2</td> </tr> </table> </center> </div>
This will center-align the table within the <div>
element.