This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes <br /> or <br> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "<br /> or <br>" Watch "<br /> or <br>" New topic
Author

<br /> or <br>

Grega Leskovšek
Ranch Hand

Joined: Nov 13, 2008
Posts: 53
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,


--Always, Grega from Peace refuge
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

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>.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Grega Leskovšek
Ranch Hand

Joined: Nov 13, 2008
Posts: 53
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

Joined: Jan 10, 2002
Posts: 60810
    
  65

Using a closing slash on non-content elements is likely a hold-over from xhtml.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

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

Joined: Nov 13, 2008
Posts: 53
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

Joined: Jan 10, 2002
Posts: 60810
    
  65

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

Joined: Feb 05, 2001
Posts: 17249
    
    6

I read the topic and felt cold.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Zak Ruvalcaba
author
Greenhorn

Joined: Feb 08, 2012
Posts: 12
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

Joined: Nov 13, 2008
Posts: 53
So I don't even need to use multiple="multiple", i just multiple enough?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

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
 
subject: <br /> or <br>
 
Similar Threads
help me to make menu list float in CSS
Using JS to maintain the scroll position of a DIV upon postback
Dropdown list
a question about arrays
Getting this same error all the time "Exception in thread"