I was just testing this and in both IE8 & Chrome I see the same thing, empty (styled) divs are rendered differently depending which way you do it. It annoys me because the former seems so much neater.
Why?
EDIT: thanks for the clarifications on XHTML Vs HTML. Currently I have this:
<html>
<head>
<meta http-equiv="Content-Language" content="en-gb" />
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title>Test</title>
What is a better choice? I'd prefer XHTML as I believe it's a bit nicer.
The <div> tag defines a division or a section in an HTML document. The <div> tag is used as a container for HTML elements - which is then styled with CSS or manipulated with JavaScript.
The <div> tag is a block level element. The <span> tag is an inline element. It is best to attach it to a section of a web page. It is best to attach a CSS to a small section of a line in a web page.
The Div is the most usable tag in web development because it helps us to separate out data in the web page and we can create a particular section for particular data or function in the web pages. It is used to the group of various tags of HTML so that sections can be created and style can be applied to them.
DIV is a generic block level container that can contain any other block or inline elements, including other DIV elements, whereas P is to wrap paragraphs (text).
In XHTML (served with Content-Type
of application/xhtml+xml
), <div />
would indeed work. But in HTML mode (text/html
), then no; HTML is not XML, and XML empty tag syntax is not recognised.
<div />
is invalid markup. Since a div can't be self closing (it would just render an empty div), some browsers might render it differently. The HTML 4.01 specs state that divs (and spans) have to have both a start and end tag.
Also take a look at this question.
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