Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML element with double attribute

Tags:

html

(The question below is hypothetical, but for reading convenience I'll ask as if I'm actually doing it)

I'm building a site in HTML 5. Unfortunately, IE doesn't support HTML5 elements like "header" and "nav". I was hoping it would treat them like generic "div"'s, but it doesn't. It simply acts as if they aren't there (meaning no CSS is applied to them).

I'd like to fix this by serving IE some dynamically transformed HTML. I'll just use the regular string replacement functions (of PHP, not that it matters) to replace all occurences of

<header>

with

<div class="header>

and so forth (an I'll transform the CSS accordingly). This should be fine, but what about this:

<header class="foo">

With the simplest replace code, this would become

<div class="header" class="foo">

Is that legal in HTML? And will the attribute then end up being "header foo" or just one of them?

(Yes, I do know that the normal way to get multiple classes is

<div class="header foo">

)

like image 877
Bart van Heukelom Avatar asked Apr 15 '26 11:04

Bart van Heukelom


2 Answers

No, you can only have one class attribute - like this:

<div class="header foo">

If you have two or more class attributes, I think it just uses the first one.

like image 56
Greg Avatar answered Apr 17 '26 20:04

Greg


If this is processed as XHTML it will be not-well-formed and throw an error and I would expect any conformant HTML parser to do this.

like image 41
peter.murray.rust Avatar answered Apr 17 '26 22:04

peter.murray.rust