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?
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.
<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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With