Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<br/> vs <div/> in clearing

Tags:

What is the difference

<br style="clear:both;"/> 

vs

<div style="clear:both;"/> 

??

Also, I thought

<div style="clear:both;"/>  

is a good way of clearing, but is

<div style="clear:both;"> </div> 

a proper way?

like image 305
codingbear Avatar asked Mar 26 '09 17:03

codingbear


People also ask

Should I use div or br?

A div is a generic container. A br is a line break. Neither is particularly well suited for expressing a section break. HTML 5 introduces sections.

What is the difference between BR and div?

<div></div> is a container of html elements <br> is line break which which starts with new line, it is used at the time of using inline level elements such as input, span, a etc.

Should I use br or br />?

In HTML, a line break is made with the <br> tag. We don't need to close <br> because it's an empty tag. To break a line, either <br/> or <br></br> are acceptable. However, <br /> tags are used in other web documents like XHTML.

What does br /> do?

The <br> HTML element produces a line break in text (carriage-return). It is useful for writing a poem or an address, where the division of lines is significant.


1 Answers

The difference is which other style attributes you inherit. Of course one inherits from <br> and the other from <div>.

Typically <div> has no special style implications other than display:block whereas <br> implies a line-break and some non-zero height (linked to the current font height).

But often (e.g. with the ubiquitous css-reset technique) there is approximentally no difference. Therefore, pick the one that makes the most semantic sense.

[UPDATE]

For closing tags, use <div></div> and not <div/>. Here's why.

Thanks to commentors Sebastian Celis and ephemient for the "closing tag" correction.

like image 61
Jason Cohen Avatar answered Sep 23 '22 10:09

Jason Cohen