CENTER ALIGN HTML CSS TAG

CENTER ALIGN HTML CSS TAG CENTERED TEXT, IMAGES, <P> ELEMENTS TUTORIALS EXAMPLES AR3SCHOOL


The HTML <center> tag is used to center the text horizontally in the HTML document. Since this tag was removed in HTML5, it is recommended that you use the CSS text-align property to format the text horizontally in the document. This tag is also commonly referred to as the <center> element.


Example 1 (CSS alternative)

<p style="text-align:center">

  This line will be centered.<br />

  And so will this line.

</p>


Example 2 (CSS alternative)

<div style="text-align:center">

  This text will be centered.

  <p>So will this paragraph.</p>

</div>


Example 3 center syntax

<center>

  This text will be centered.

  <p>So will this paragraph.</p>

</center>


Example 4 Center-align text (with CSS):

<html>
<head>
<style>
h1 {text-align: center;}
{text-align: center;}
div {text-align: center;}
</style>
</head>
<body>

<h1>This is a heading</h1>
<p>This is a paragraph.</p>
<div>This is a div style</div>

</body>
</html>



How To Center HTML Images?

Step 1) Add HTML:

Example
<img src="paris.jpg" alt="Paris" class="center">


Step 2) Add CSS:

To center an image set the left and right margins to auto and make it into a block element:

Example
.center {
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: 50%;
}

Comments :

Post a Comment