HTML Elements – Block vs Inline Elements and Their Distinction

csshtml

The distinction between block and inline elements always seemed strange to me. The whole difference is that a block element takes up the entire width thus forcing a line break before and after the element, and an inline element only takes up as much as the content. Why not just have one type of element- an inline element where you can also apply custom height/width, and use that? You want line breaks? Insert a <br />, or maybe add a special tag in the CSS for that behavior. The way it's now, I don't see it solving any problem, and instead it only forces a property that in my opinion should be decided by a designer.

So why the two types?

Best Answer

You say:

You want line breaks? Insert a <br />, or maybe add a special tag in the CSS for that behavior. The way it's now, I don't see it solving any problem, and instead it only forces a property that in my opinion should be decided by a designer.

You are on the right track - style should be decided by the designer.

But, you've got the problem the other way around. Inserting a <br/> tag is actually the option that "forces a property that should be decided by a designer" — inside the markup document, once the <br/> is there, it's there - and only with some tricky/hacky CSS can you remove its effect.

Inline/block elements, on the other hand, are purely elements styled with a convenient default for the common use case. The visual property itself can be changed instantly by a CSS designer with display:inline or display:block.

Take for example the common element for navigation these days - <li>. These are by default block elements, but designers will make them float to appear inline (block has more special properties than just taking up the whole line, but that's a conversation for another day).

Related Topic