Javatpoint Logo
Javatpoint Logo

CSS Center image

A common task in CSS is the centering of images or texts.

To center an image, we can use the CSS properties like margin:left, margin-right, and block CSS properties.

The <img> element is said to be an inline element that can easily be centered by applying the text-align:center property of CSS to the parent element that contains it.

Using the text-align:center property, we must have to place the <img> element within a block-level element such as div. It is because we can apply the text-align:center property only to the block-level elements. It will center the image horizontally.

Let's understand it by using an illustration.

Example

Test it Now

Let's take another example of centering the image in which we will use the text-align:center property.

Example

Test it Now

Next TopicCSS Opacity




Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA