HTML center

In two ways, text can be done in the center, one way is with HTML Center Element <center> Tag, and the other is the CSS property. Let’s know how you can use both methods and how to center text in HTML.

.myclass {
	text-align: center;
}

<div  class=”myclass” >
	<p>Please keep center my text</p>
</div>

< center >Please keep center my text</ center >

Note that the HTML Center Element <center> Tag does not work in HTML5.

HTML Center Examples

.myclass {
text-align: center;
}

<div  class=”myclass” >
	<p>Please keep center my text</p>
	<h2>Please keep center my text</h2>
</div>

< center > Please keep center my text, <p> Don’t be in left or right </p></ center >


p {
	text-align: center;
}
h1 {
	text-align: center;
}
div {
	text-align: center;
}
span {
	text-align: center;
}


OR

p, h1, div, span {
	text-align: center;
}

How To Center An Image In HTML

If you want to center your image like your text, then there are 4 easy ways for it. Let’s know how to center an image in HTML.

/ ***** Way 1 *****/

.myimage {
	text-align: center;
}

<div  class=”myimage” >
	<img src=”/your-image.jpg”>
</div>


/ ***** Way 2 *****/

.myimage {
	margin: 10px auto 20px;
	display: block;
}

<img class=”myimage” src=”/your-image.jpg”>

/ ***** Way 3 *****/

.myimage {
	left: 50%;
	transform: translate(-50%, -50%);
	position: fixed;
	top: 50%;
}


<div class=”myimage”>
	<img src=”/your-image.jpg”>
</div>

/ ***** Way 4 *****/

<center>
	<img src=”/your-image.jpg”>
</center>

Browser Support

  • Edge
  • Firefox
  • Chrome
  • Internet Explorer
  • Opera
  • Safari

Frequently Asked Questions

We have answers to some questions that people search on the Internet everyday. Let us know what are those questions and what are their answers.

How do you center text in HTML CSS?

With the <center> Tag and the text-align: center property, you can center the text.

How do I center an image in a div?

For this, you have to use 2 properties of CSS. Such as margin: auto and display: block.

How do you bold something in HTML?

To make the text bold, you have to use <b> tag or <strong> tag.

How do you hyperlink in HTML?

You can create a hyperlink with <a> tag and href attribute.

How do you link HTML and CSS?

To link css with html you have to use <link> tag. For example <link rel = “stylesheet” href = “mystyle.css”>.

What is div in HTML?

In simple language, div is a box inside which you set your elements.

Where do I put CSS in HTML?

There are 3 ways to apply CSS, either you can link your file inside the head tag, or you can add inline CSS, or you can place your CSS on the same page with the style tag.

Note: All the examples shown in this article, we have tested before, you can use these examples without any difficulty.

Related: 5 Easiest Example Of Applying CSS Letter Spacing Property