Why using <span class="underline"> instead of u-tag?

122 views
Skip to first unread message

Franz

unread,
Oct 11, 2011, 4:58:36 AM10/11/11
to Trac Development
Hi,

as I extended the CKEditorPlugin for Trac, I found that Trac formats
underlined text by this line of code:
<span class="underline"> As far as I understand this is defined in
http://trac.edgewall.org/browser//trunk/trac/wiki/formatter.py#L409

CKEditor uses the u-tag for underlined text, so there is a difference,
which has to be handled.

But why are you using the span-tag, when there is a u-tag? Isn't the u-
tag the official / nicer solution?

Best regards,
Franz

Eirik Schwenke

unread,
Oct 11, 2011, 6:20:24 AM10/11/11
to trac...@googlegroups.com

I can't answer for the decision by the trac-team to use the span tag --
but in general there are two approaches to html -- the "old" one and the
"new" semantic model.

In general tags like <b> (bold) and <u> (underline) have been phased out
in favour of semantic tags like <em> (emphasis) and <strong>. This is a
"write what you mean, not what it might look like" approach.

This separation between semantics and style is part of the design behind
css. One might argue that using a span is the worst of both worlds --
but at least the span tag is intended for adding among other thing
visual style to a document without complicating the document structure.

There are two reasons for this; a) making the html document more easily
machine readable, and b) because of a) makking the html document easier
to render "with it's intended meaning" by a user-agent for a user.

Eg: In Japanese, there is no meaningful "underline", and emphasis is
often made by using a different script (katakana) (Not that I know of
any browser that renders <em> as katakana -- but it would be possible in
theory).

Similarly a screen reader might try to emphasise a word verbally --
rather than reading "underline, word, underline stop" or something similar.

So, no. the "u"-tag isn't necessarily a better/more official approach.


Best regards,

--
.---. Eirik Schwenke <eirik.s...@nsd.uib.no>
( NSD ) Harald Hårfagresgate 29 Rom 150
'---' N-5007 Bergen tlf: (555) 889 13

GPG-key at pgp.mit.edu Id 0x8AA3392C

signature.asc

Christian Boos

unread,
Oct 11, 2011, 4:34:32 PM10/11/11
to trac...@googlegroups.com
Hello,

On 10/11/2011 10:58 AM, Franz wrote:
> Hi,
>
> as I extended the CKEditorPlugin for Trac, I found that Trac formats
> underlined text by this line of code:
> <span class="underline"> As far as I understand this is defined in
> http://trac.edgewall.org/browser//trunk/trac/wiki/formatter.py#L409

Blame is your friend ;-)

See http://trac.edgewall.org/changeset/129

So nearly since the beginning of the project, we use XHTML 1.0 Strict in
which there's no <u> tag; it's only present in XHTML 1.0 Transitional.

Same thing for HTML, it was in 3.2 but no longer in 4.0. Not so
surprisingly it was reintroduced in HTML5, though it comes back with a
warning:
Note: The default rendering of the u element in visual presentations
clashes with the conventional rendering of hyperlinks (underlining).
Authors are encouraged to avoid using the u element where it could be
confused for a hyperlink..

So until we switch to HTML5, there's no point in reintroducing <u> ;-)

-- Christian

Reply all
Reply to author
Forward
0 new messages