
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
Center image using text-align center with CSS?
The text-align center is generally used to center text of an element. Let us see an example wherein we have centered a heading using the text-align center.
Center a text using text-align property in CSS
In this example, we have centered a heading using the text-align property −
h1 { text-align: center; }
Example
Let us now see the example to center a text −
<!DOCTYPE html> <html> <head> <style> h1 { text-align: center; } </style> </head> <body> <h1>Demo Heading</h1> <p>This is demo text.</p> </body> </html>
Output

Center an image using text-align property in CSS
Let us now see how to center an image using text-align property in CSS. The center value of the textalign property is used for this −
.myimg { text-align: center; }
Here’s our image under div −
<div class="myimg"> <img src="https://www.tutorialspoint.com/jsf/images/jsf-mini-logo.jpg" /> </div>
Example
Let us now see the complete example to center an image −
<!DOCTYPE html> <html> <head> <style> .myimg { text-align: center; } </style> </head> <body> <h1>Centering an Image</h1> <div class="myimg"> <img src="https://www.tutorialspoint.com/jsf/images/jsf-mini-logo.jpg" /> </div> </body> </html>
Output

- Related Articles
- Center an image with CSS
- How to align text content into center using JavaScript?
- How to position text to center on an image with CSS
- How to center an image with CSS?
- Usage of CSS align-content property center value
- Usage of CSS align-items property center value
- How to center align component using BoxLayout with Java?
- Align flex items at the center of the container with CSS
- How to Align Column DIVs as Left-Center-Right with CSS Flex
- How to center align text in table cells in HTML?
- How to align flexbox container into center using JavaScript?
- How to Align Navbar Items to Center using Bootstrap 4?
- How do I center tag using CSS?
- Align a flex item in the center with Bootstrap 4
- Align single rows of items in the center with Bootstrap 4

Advertisements