Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align Attribute Deprecated

I found out a while back that the center tag was deprecated. Understandable because HTML is meant for structuring content and not so much for formatting. But why is the align attribute deprecated too? Attributes can be used for formatting. I understand that CSS can be used, but not everyone knows CSS. And to make it worse, text-align:center; and margin-left: auto; margin-right: auto; doesn't always center objects, but using pretty much always works.

Here's the Post from the W3C on this: http://www.w3.org/TR/html4/present/graphics.html#h-15.1.2

On a site I'm working with we are using the latest doctype (). Should I try my best not to use the align attribute? Is CSS the only safe way to center objects? I'm trying to make sure content is secure for the future.

like image 620
Josh Lewis Avatar asked Jan 27 '13 19:01

Josh Lewis


People also ask

Is align attribute deprecated?

As noted earlier, HTML 4 deprecated the align attribute, which was previously used to align text, tables, cell contents, other objects, and position captions. CSS replaces this with the text-align property for text.

Why align attribute in HTML is not working?

align only works on block level element like div,p etc. In html5, align attribute of img tag is not supported. <center> tag can also have problems. Best way is to use align attribute on a div, p, span or other container and put img inside that.

Is text-align deprecated?

This tag has been deprecated in HTML 4 (and XHTML 1) in favor of the CSS text-align property, which can be applied to the <div> element or to an individual <p> . For centering blocks, use other CSS properties like margin-left and margin-right and set them to auto (or set margin to 0 auto ).


1 Answers

Yes, CSS should be used for that. I can't think of a single reason why it would be better to use an HTML attribute for alignment instead of a CSS rule. And if you don't want to learn CSS (which is fine), you might want to consider using a CSS framework like Twitter Bootstrap, especially the scaffolding part. It will save you a ton of time, make your site look good from the get go, and let you apply custom themes in a consistent fashion whenever you grow tired of the default one.

like image 58
Ismael Ghalimi Avatar answered Sep 28 '22 01:09

Ismael Ghalimi