Image Align Attribute in HTML 5

Image align attribute in HTML 5

Use CSS's vertical-align property, specifically vertical-align: middle

<img src="image.png" style="vertical-align:middle" />

Demo

See this page for more information on Aligning inline images with the vertical-align property

HTML5 - img alignment centre not working

align attribute for the image is aligning it relativelly to the text or other images on webpage (for more info: https://www.w3schools.com/tags/att_img_align.asp).

And notice (info from w3schools):

"The align attribute of is not supported in HTML5. Use CSS instead."

So align attribute will not do the trick in your case, you can center image using:

img {
display: block;
margin: 0 auto;
}

instead. Here is an example:

img {  display: block;  margin: 0 auto;}
<header>  <h1> Luke Johnson Portfolio</h1>  <div class="image-cropper" style="text-align">    <img src="https://pbs.twimg.com/profile_images/378800000017423279/1a6d6f295da9f97bb576ff486ed81389_400x400.png" alt="Luke Profile Pic" class="rounded" />  </div></header>

Align an image inside paragraph in HTML5

You can use

p img{
float: left;
}

This rule will apply on all images under <p>

p img{  float: left;}
 <p>        <img src="https://fakeimg.pl/30x30/?text=A"/>        some long text    </p>

Is the attribute align legal to use in HTML5?

No in HTML5 align attribute is deprecated. Though, you can use style sheet text-align property.

In case of deprecated valign attribute, you can use vertical-align property.

Also, if you going to make flex box, use align-content property to align contents.

Why does attribute align=center work in my html5 file?

The Doctype is used only to switch between standards and quirks modes.

Browsers support obsolete elements and attributes for the sake of backwards compatibility.

This is explicitly mentioned in the HTML specification which says:

The following rules are also expected to apply, as presentational hints:

p[align=center i], h1[align=center i], h2[align=center i], h3[align=center i],
h4[align=center i], h5[align=center i], h6[align=center i] {
text-align: center;
}

Do note, however, that the spec also says:

The following attributes are obsolete (though the elements are still part of the language), and must not be used by authors:

Align attribute still available in HTML5?

As Mike W pointed out in the comments:

The align attribute is deprecated in HTML 4, and removed in HTML 5.
Don't use it: use CSS instead.

That being said, here are some ways to center it anyway, even though you say you have more elements with that class.

Give this specific element inline style:

<div class="main" style="margin: auto;">

Be more specific in your CSS. The element is probably a child of an element that does not have any other .main babies, so you can specify this element by using the parent element in CSS:

.parent-class > .main {margin: auto;} /* If the parent has a class */
#parent-id > .main {margin: auto;} /* If the parent has an ID. This one is prefered, to avoid misunderstandings */

If the above is not the case, and there are multiple instances of .main within a single parent, you can use the nth-child selector (or first-child or last-child). For instance, if the element you want to center is the third child within the parent element, use this code.

.main:nth-child(3) {margin: auto;}

HTML img align=middle doesn't align an image

How about this? I frequently use the CSS Flexible Box Layout to center something.

<div style="display: flex; justify-content: center;">  <img src="http://icons.iconarchive.com/icons/rokey/popo-emotions/128/big-smile-icon.png" style="width: 40px; height: 40px;" /></div>

Correct CSS to replace img align element

There's a few options. The best probably is to set the style on those elements to use margin: auto;

margin-left: 50%;
margin-right: 50%;
margin: auto;

In the case of one of your images, for example, it would look something like this:

<img style='margin-left: 50%; margin-right: 50%; margin: auto;' src=... />

Of course, you should just put the css in a class and set the class of anything you want centered to that class. The css class would look like:

.centered {
margin-left: 50%;
margin-right: 50%;
margin: auto;
}

Center image using text-align center?

That will not work as the text-align property applies to block containers, not inline elements, and img is an inline element. See the W3C specification.

Use this instead: