File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

<br /> or <br>

 
Grega Leskovšek
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We all used <br> along time ago and then for a long time also <br /> over <br/>
Does HTML5 defines that empty elements should not be closed?
I mean should we use <br> and <img src="" alt=""> again with no closing slash?
Thanks in advance,
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTML5 defines both ways as equally valid.

Personally, I follow the convention that elements that cannot contain content are not self closed (so <br>, <img>, <input>) and elements that can contain content but are empty follow: <div></div>.
 
Grega Leskovšek
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a recommendation - w3c or whatever? O'Reilly School of Technology told me that empty elements shouldn't be closed?
I would say without slash it is simpler, faster, but most of the web today closes the empty tag?
What are You using?
--->thanks, I just read Your post
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using a closing slash on non-content elements is likely a hold-over from xhtml.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A few more of my person style choices: I always use all lowercase (nothing makes HTML less readable and more like it's from 1998 than using all uppercase), and I always quote attribute values whether they need it or not.

Essentially, all my style choices come down to what I feel gives the markup the greatest degree of clarity and readability.
 
Grega Leskovšek
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a difference when using single or double quotes? like <img src="" alt=''>
Is it true that both works equally? I prefer double quotes. Thanks,
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened when you tried either way?

Personal usages: I prefer " for attribute values unless there's a reason to use ' (e.g. avoid JSP syntax problems, avoid needless escaping).
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read the topic and felt cold.

Mark
 
Zak Ruvalcaba
author
Greenhorn
Posts: 29
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At the moment it's personal preference. There's nothing that says you should or should not close empty elements like <hr>, <br>, <input>, etc. With that said, as a general rule of thumb, I no longer use the trailing forward slash on empty elements. The rule is a hold over from XHTML and it has always bothered me. The trend in HTML is to remove as much markup as you can from the document (either by eliminating unnecessary code, using lighter HTML5 syntax, differing to CSS (and CSS type selectors) whenever possible, etc.) as possible...obviously to improve load time, page-to-page browsing efficiency, and footprint on mobile devices. It always seemed to me that adding the unnecessary forward slash was just....well...unnecessarily bloating the size of the page by adding characters that were not needed. When HTML5 was in its infancy...there was a debate about whether or not to continue on with the main XHTML rules (lowercase tags, close all attribute values in quotes, close empty elements, add the value to Boolean attributes (example <input type="text" disabled="disabled">. Long story short, for a while we had what was referred to as "polyglot HTML5" which was HTML5 using syntax rules of XHTML. More and more the trend is going away from this and back to the old writing style of HTML 4.

Zak
 
Grega Leskovšek
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I don't even need to use multiple="multiple", i just multiple enough?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, just multiple is enough. The rest is redundant and needless. And, in fact, very confusing. That's always bothered me about xhtml.

Take for example something I've seen a lot of: the disabled attribute expressed as disabled="true". That will work just fine to disable the element. But that leads one to believe that disabled="false" will not disable the element. But it does. Why? Because in xhtml, the value doesn't matter, there just needs to be one to satisfy XML rules. It's the presence of the disabled attribute with any value that disables the element. It's much clearer to just have disabled.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic