May 15, 2013

HTML tags or CSS properties

K_programmer’s Question:

So I was wondering what’s better to use – HTML tags or CSS properties?

We have both HTML tags and CSS properties for same purpose in various cases, like in <img> tag one can use width and height html values to assign them or can use css properties for same purpose.

Then, to center some text, or some other contents too, one can use <center>Some text here</center> or css property text-align:center;

To make some text italic, one can use <i> or <em> html tag or use equivalent css properties. (Though <i> has a different meaning in HTML5, but still it’s used.)

There are many similar cases. So, what’s more acceptable and better to use?

In this age of HTML5, I would opt to not use any HTML attributes that were already marked deprecated for its predecessors HTML 4.01 and XHTML, such as width, border, height etc.

For layout, use CSS, for semantics, use HTML. The border attribute serves no other purpose nowadays than enable legacy IE5.5 sites to still work.

As for the questions about <i> and <b> I’d recommend reading up a bit on why you should only write semantic HTML, for example here.

More general reading about why HTML is not for layout/presentation can even be found on Wikipedia.

This topic is quite debatable in my opinion. HTML tags and its attributes have a semantic meaning behind it where as CSS is entirely focused on the layout and styles. HTML5 adds a new brand semantic tags.

Tags like <strong> have much more meaning then font-weight:bold. The css property only makes the text appear bold, but the HTML tag <strong> strengthens the content (You can see the difference through a text reader).

However, new generation of web focuses more on the style than on the HTML structure, so there is not a fixed rule on how it should be followed. So I suggest concentrating one factor and that is manageability. Select the option which you can manage and maintain easily.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!