Is the following valid HTML?
<br class="something">
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.
Yes.
See the specification.
The class
attribute applies to "HTML Elements" (which includes br
elements).
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" }
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.
Yes, it's valid statement. you could use something like.
<br style="height: 100px; margin-top: 10000px;">
But instead using div element is recommended.
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.
It is valid in HTML 4.01, because the class
attribute is allowed for the br
element. It is also valid in HTML5 in HTML serialization, because the class
attribute is allowed for all elements. It is not valid XHTML without a matching </br>
.
Yes, you can add a class
attribute to a <br>
element. id
as well if you want.
Sure, it's valid. A useful example would be if you wanted to visually add a little space after a line-break, without ending the paragraph. Or perhaps apply a background image. All sorts of styling options.
a br
tag doesn't produce a CSS box and hence little can be done with it.
Only practical case is clear
. i believe drupal used it at some time. interestingly CSS 1 spec. refrained from doing anything to br. http://www.w3.org/TR/REC-CSS1/#br-elements. no doubt applying some css on it doesn't invalidate the code but will cause little effect.
this https://stackoverflow.com/a/899359/1043824 is a good discussion on the topic.
For poetry in single line lyrics you can use br class="hanging" to cause the line to wrap only on a narrow screen such as a phone, but not on wider widths, thus preserving the line breaks of the poet, which really really matters to them, while still allowing text to flow freely, which matters to me
It does come handy when you want to omit the linebreak.e.g in a Headline when having a responsive layout and certain breakpoints.
`, if for example I want to remove a line break in mobile view. – b00t Jun 22 '16 at 08:43