HTML5 Self Closing Input Tag

1,094 views
Skip to first unread message

ludicco

unread,
Nov 23, 2009, 8:39:25 AM11/23/09
to Haml
Hello there,
I'm not sure about this, but I'm having problems while using html5 in
haml. It looks like that the input tag is not being closed.
so if I have:
%input#search{:type => 'text', :name => 'q', :value => 'search
website'}

it generates:
<input id='search' name='q' type='text' value='search website'>

I already tried
%input#search{:type => 'text', :name => 'q', :value => 'search
website'}/
or even:
set :haml, { :format => :html5, :autoclose => ['meta', 'img',
'link','br', 'hr', 'input', 'area', 'param', 'col', 'base'] }

but nothing happens

Is there any way to make it work?

thanks

Mislav Marohnić

unread,
Nov 23, 2009, 9:05:17 AM11/23/09
to ha...@googlegroups.com
On Mon, Nov 23, 2009 at 14:39, ludicco <mar...@ludicco.com> wrote:
Hello there,
I'm not sure about this, but I'm having problems while using html5 in
haml. It looks like that the input tag is not being closed.

Somebody correct me if I'm wrong, but the input tag (like many other tags) doesn't have to be closed. In fact, forcing it to render a self-closing tag makes no sense unless you're using XHTML.

If you want to write your HTML5 with an XHTML syntax, tell Haml to render your templates as ":format => :xhtml" and use "!!! 5" to get a HTML5 doctype (you need the newest stable version).

ludicco

unread,
Nov 23, 2009, 12:51:43 PM11/23/09
to Haml
Thanks for the tip Mislav, yes I see your point, but the thing is, if
it's optional, why not fill this 'optional'?
or why don't let the user decide if he wants its closed or not (even
with :autoclose)?
Particularly I don't see a point in make the closing tag "optional" in
html5 (I know this is not a haml approach but the markup's), I think
this tends to causes confusion and this is opposed as 'standard' in my
opinion.
I can agree for html4 and older, but now we have more markup standards
and everything, so why keep using the old way to do it?
Maybe I'm missing something but I really don't see why you should
leave something you create opened, or better, whats the side effect of
closing it?
If there is a side effect, so I would change my mind on it, otherwise
I think this is really pointless.
Again, I'm not sure If I'm missing something about html5 markup style.
this is just my opinion as HAML could render the tags, helping to
maintain a 'standard' all over the document

Nathan Weizenbaum

unread,
Nov 23, 2009, 1:54:19 PM11/23/09
to ha...@googlegroups.com
Self-closed tags are not valid HTML syntax. The proper syntax is to leave off the end tag and leave it at that, which is what Haml does. Haml won't render invalid HTML. If you want XHTML syntax, use :xhtml as Mislav suggested.

--

You received this message because you are subscribed to the Google Groups "Haml" group.
To post to this group, send email to ha...@googlegroups.com.
To unsubscribe from this group, send email to haml+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/haml?hl=.



Norman Clarke

unread,
Nov 23, 2009, 2:32:37 PM11/23/09
to ha...@googlegroups.com
On Mon, Nov 23, 2009 at 2:51 PM, ludicco <mar...@ludicco.com> wrote:

> Thanks for the tip Mislav, yes I see your point, but the thing is, if
> it's optional, why not fill this 'optional'?
> or why don't let the user decide if he wants its closed or not (even
> with :autoclose)?
> Particularly I don't see a point in make the closing tag "optional" in
> html5 (I know this is not a haml approach but the markup's), I think
> this tends to causes confusion and this is opposed as 'standard' in my
> opinion.
> I can agree for html4 and older, but now we have more markup standards
> and everything, so why keep using the old way to do it?

The reason self-closing tags are supported in HTML 5 is for backwards
compatibility with XHTML, and for authors who want to create documents
that can be checked against an XML validator.

HTML 5 loosens a restriction of XHTML, in that, a valid HTML document
does not need to be a valid XML document.

So worrying about having "<br />" rather than "<br>" is pointless
unless you're validating your document as XML. Using self-closing tags
in HTML 5 is pretty much the equivalent of using semicolons in Ruby,
and I would guess you're only doing it out of habit. If you're doing
HTML 5 and want to be consistent, then I would recommend not using
self-closing tags unless you have a compelling technical reason to do
so.

--Norman

Mislav Marohnić

unread,
Nov 23, 2009, 7:30:48 PM11/23/09
to ha...@googlegroups.com
On Mon, Nov 23, 2009 at 18:51, ludicco <mar...@ludicco.com> wrote:
Again, I'm not sure If I'm missing something about html5 markup style.
this is just my opinion as HAML could render the tags, helping to
maintain a 'standard' all over the document

For me, a great thing about Haml is that there is no "coding style". In your Haml source there is the syntax that Haml enforces, and nothing more. You never have to check your output. Why? Because you can be confident that Haml does the right thing (if you specified the right format). You don't have to maintain a coding style in your final HTML because you never actually wrote any HTML.

Eric Meyer

unread,
Nov 23, 2009, 8:00:19 PM11/23/09
to Haml
Mislav,

If the point is that you don't need to worry about it because HAML
does, I can see some point to that. I'm sure HAML code is consistent.
But I think we should clearly be worried about having easily readable
and maintained output. I want to know that my clients can hire any
damn web designer they want next year without being tied to an extra
technology just because I liked it. That means means my HTML/CSS need
to be just as pretty as my HAML/SASS (though I don't actually use the
HAML side of that equation).

Self-closing tags aren't "required" in HTML5, but I always thought
they made more sense. I keep them in all my HTML5 code (most of what I
do these days), and it isn't because I have to validate as XML - it is
because it makes the document more readable.

Norman Clarke

unread,
Nov 23, 2009, 8:41:36 PM11/23/09
to ha...@googlegroups.com
On Mon, Nov 23, 2009 at 10:00 PM, Eric Meyer <erii...@gmail.com> wrote:

> Self-closing tags aren't "required" in HTML5, but I always thought
> they made more sense. I keep them in all my HTML5 code (most of what I
> do these days), and it isn't because I have to validate as XML - it is
> because it makes the document more readable.

That's because you're used to doing XHTML. Which is fine. But seriously,

<meta content="en-us" http-equiv="Content-Language" />

is barely visually different from:

<meta content="en-us" http-equiv="Content-Language">

and the number of tags which self-close in XHTML is so small that if
you know what they mean, you can keep them in your head. If you know
HTML well, this code should look ridiculous to you:

<br>content here</br>

So why do you need the trailing slash to tell you not to expect nested
content after a <br>? You don't - it was never included for
readability, it was included for compatibility with XML. I would go so
far as to say it was included *despite* the fact that it made
documents uglier and less readable. But I started working with HTML
3.0 so I guess that's my bias. :)

In any event, this is a solved problem in the latest Haml, if you want
HTML5 self-closing tags just use Haml's default settings and "!!! 5"
for your doctype.

--Norman

Eric Meyer

unread,
Nov 24, 2009, 1:22:36 AM11/24/09
to Haml
I'm not actually used to XHTML - didn't like the way it was served so
I used HTML - just always liked those closing slashes. Always thought
the stricter, more formal rules of coding made more sense. But I'm
happy for people to have different taste on that. Main point was just
that I think we should care how our output code looks.

I love these tools, but I think it's important to remember that
whatever tools (frameworks/meta-languages) we use to write, we're
writing HTML and CSS. Those are what matter once we're done, and what
we leave the client with. I want to write my own code, otherwise I
might as well just be slicing it up in GoLive. I like SASS because I
get the speed of a framework, but I know every line of the output when
I write it. Awesome.

Cheers,
-e



On Nov 23, 6:41 pm, Norman Clarke <com...@gmail.com> wrote:

Nathan Weizenbaum

unread,
Nov 24, 2009, 2:15:16 AM11/24/09
to ha...@googlegroups.com
Haml certainly values the look and feel of the HTML output. That's why we go to such pains to properly indent everything and produce valid code. But it also cares about conventions, and the convention for writing HTML5, like other versions of HTML, is clearly not to include the closing slash. This is a minor enough formatting preference that I don't think it's worth adding a configuration option specifically for it, especially when currently the :xhtml format option does exactly this.

2009/11/23 Eric Meyer <erii...@gmail.com>
--

You received this message because you are subscribed to the Google Groups "Haml" group.
To post to this group, send email to ha...@googlegroups.com.
To unsubscribe from this group, send email to haml+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/haml?hl=en.



Mislav Marohnić

unread,
Nov 24, 2009, 5:48:19 AM11/24/09
to ha...@googlegroups.com
I actually wrote a Rails plugin that overwrites Rails view helpers to prevent them rendering self-closing tags (Rails was oriented towards "XHTML" output from the start): http://github.com/mislav/standardista

ludicco

unread,
Nov 24, 2009, 11:22:48 AM11/24/09
to Haml
Thanks everybody for your inputs, Its really well appreciated :) and
good at the same time because this is a kind of subject that it's not
about HAML but to helps us learn what HAML does and how a proper
document should be formatted. Now I can see the point of required,
after what Norman Clarke said. But I also agree with Eric in leaving
the self closing because it looks better organized, actually I think
that too because the problem in this case to leave opened tags would
be the indentation, HAML it's easy for me to understand because of the
indentation so that's why I know when a tag is closed but how would
you supposed to know if you have something like this:

<input type='text' value='username'>
<label> password:</label>
<a href='/'> Forgot your password?</a>
<input type='text' value='password'>

that in my point of view would generated something like this:
<input type='text' value='username'>
<label> password:</label>
<a href='/'> Forgot your password?</a>
<input type='text' value='password'>

so on a plain document how would you know when it is finished or not?
So the thing is that I agree with both sides, but visually speaking
this is far unorganised than self closing I think.
Obviously I'm not here to criticise HTML5, because I really think this
will be a revolution (its already is) and I really like, I know this
isn't the right place to discuss about it so I will leave for another
context.
But it was very good to receive lots of information from you. I can
understand much better now

:)
Thanks again
Reply all
Reply to author
Forward
0 new messages