Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centering an image link with HTML and no CSS

Tags:

html

I am trying to center an image using only HTML and no CSS, is this possible? I have tried the following code:

<a href="link">
<img src="URL" align="center"></a>

However the image doesn't move. How can I solve this?

The image I am trying to center is the donate button on the right column of our blog I am placing the link in a "text" widget so the CSS doesn't seem to work there.

like image 723
Arthur Mamou-Mani Avatar asked Jun 03 '13 22:06

Arthur Mamou-Mani


People also ask

How do you center a link on a picture in HTML?

Step 1: Wrap the image in a div element. Step 2: Set the display property to "flex," which tells the browser that the div is the parent container and the image is a flex item. Step 3: Set the justify-content property to "center." Step 4: Set the width of the image to a fixed length value.

How do I center a list without CSS in HTML?

There are many options to center <div> in HTML. Using attributes : <div style=”margin: auto;”></div> <div style=”align-items:justify;”>

How do I align an image in HTML?

We use <img> align attribute to align the image. It is an inline element. Attribute Values: left: It is used for the alignment of image to the left.

Can you center something in HTML?

One way to center text or put it in the middle of the page is to enclose it within <center></center> tags. Inserting this text within HTML code would yield the following result: Center this text!


3 Answers

Well, you could use <center>, but it is no longer supported. Your best bet here is to use the style attribute in HTML and text-align:center. This won't directly center the image, so you would wrap it in a div with the styling:

<div style="text-align: center">
<a href="link">

<img src="URL" align="center"></a>
</div>

After looking at a comment that was posted, I see that you actually don't need the div. Just apply it to the link around it.

<a href="link" style="text-align: center">

<img src="URL" align="center"></a>

There is no possible way to do this without CSS, unless you want to use outdated stuff.

like image 91
StackExchange User Avatar answered Sep 21 '22 07:09

StackExchange User


Another way that doesn't use CSS is to wrap the image in a table. While it's not the best way to do things on the Internet as it stands, but it is compliant with older e-mail clients, browsers, and systems where companies strip CSS from contents on a firewall.

<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr><td align="center">
<img src="URL">
</td></tr>
</table>

While I realize this question was about implementation in WordPress, Google thought it was relevant to my own issue.

like image 39
AbsoluteƵERØ Avatar answered Sep 21 '22 07:09

AbsoluteƵERØ


You can align the image to center by

<p style="text-align:center;"><img src="logo.png" alt="Logo"></p>

like image 39
Omkar Ghurye Avatar answered Sep 20 '22 07:09

Omkar Ghurye