Skip to content Skip to sidebar Skip to footer

Apply A Class To A Br Tag?

Is the following valid HTML?
As an HTML element I can't see why it wouldn't be, but I don't think I've ever seen it in use.

Solution 1:

Yes.

See the specification.

The class attribute applies to "HTML Elements" (which includes br elements).

Solution 2:

One application I can think off is adding using it with pseudo-elements, such as :before or :after, for instance adding some text beneath a horizotal line:

hr.something:after  { content: "Some text"  }

Solution 3:

Yes, is valid.

Specification tells that br accepts global and event attributes, and class is a global one.

Note that if you target HTML4 and below, there's an specific attribute for br named clear, which defines where to put the new line, as stated here, but now is deprecated and unless your DOCTYPE lets you, you should not use it anymore.

Solution 4:

Yes, it's valid statement. you could use something like.

<brstyle="height: 100px; margin-top: 10000px;">

But instead using div element is recommended.

Solution 5:

Yes you can, from the w3c specification : http://dev.w3.org/html5/markup/br.html

<br> element can make use of global attributes, and class is one of them.

Post a Comment for "Apply A Class To A Br Tag?"