+ 8

Why <br> is an inline element not a block level element in HTML ?

Conceptual query

24th Mar 2019, 5:56 AM
Laksheya
Laksheya - avatar
18 Respostas
+ 13
<br> is an old way of styling webpage. It doesn't incorporate good control over the degree of line separation. The modern way is by using CSS property margin-top or padding-top of the next element.
24th Mar 2019, 6:08 AM
Gordon
Gordon - avatar
+ 9
<br> is the only inline element that I know which adds a newline by default without additional CSS styling. Are there others?
24th Mar 2019, 11:32 PM
Sonic
Sonic - avatar
+ 8
Laksheya Good Question... dude... As you asked why <br/> is not a block element....The answer is as following... If you know , A block element must be started from a new line and that's rule of it on the other hand <br/> tag could be used with any other element (I mean it doesn't need to be started from a new line) ...This is just used to give a break ....So if you know : Inline elements doesn't need to be started from a new line ;
24th Mar 2019, 7:55 PM
Shourya
Shourya - avatar
+ 5
<br> is inline because it does not start on a newline but rather jump the pen to a newline
25th Mar 2019, 1:21 AM
George S Mulbah II
George S Mulbah II - avatar
+ 4
Gordon that's not the question, is it? You are free to add any style of margin or padding even to a <br> :)
24th Mar 2019, 6:22 AM
::sк::
::sк:: - avatar
24th Mar 2019, 6:37 AM
Gordon
Gordon - avatar
+ 4
Laksheya Because a mechanism for starting a new line within the same block comes in handy?
24th Mar 2019, 8:33 AM
::sк::
::sк:: - avatar
+ 4
A little elaboration on my demo : 1. Even for a block level element such as div, we can alternate its behavior by setting CSS property display as inline. (vice versa, we can set display block for inline element) 2. The space of separation between elements should be styled with margin. Never use br because you cannot style br, which will make your webpage display in a way you cannot fully control.
24th Mar 2019, 1:07 PM
Gordon
Gordon - avatar
+ 3
My attempt: Because it has to be empty, and a block element would also allow you to put any inline elements into it.
24th Mar 2019, 6:10 AM
::sк::
::sк:: - avatar
+ 3
Laksheya right, but asking the other way round: any block elements that are conceptually empty as in <div/>?
24th Mar 2019, 6:18 AM
::sк::
::sк:: - avatar
+ 3
Laksheya It's true that, if we insert br tag, we get a new line. But br tag is not a part of new line. It's an inline-block Element.
24th Mar 2019, 6:21 AM
Sarthak Pokhrel
Sarthak Pokhrel - avatar
+ 3
Gordon I am sure that demo explains something, but it doesn't say anything about the OP's question?
24th Mar 2019, 7:59 AM
::sк::
::sк:: - avatar
+ 3
Laksheya There's no such thing as an inline block element. br behaves a bit similar to img. Or think of it as a line feed character that is also kind of a non character :)
24th Mar 2019, 8:04 AM
::sк::
::sк:: - avatar
+ 3
Laksheya in response to Gordon I did a bit of googling and found an interesting thread over on SO that gives the css1 spec as well: https://stackoverflow.com/questions/899252/can-you-target-br-with-css. Examples included...
24th Mar 2019, 8:19 PM
::sк::
::sк:: - avatar
+ 2
watch the examples here about ALL block ELEMENTS and ALL inline ELEMENTS. https://www.w3schools.com/html/html_blocks.asp
24th Mar 2019, 7:00 AM
Robin R.
Robin R. - avatar
+ 2
In the linked thread above there are a few interesting options on styling br with CSS (very limited) and using is/jQuery.
25th Mar 2019, 6:03 AM
::sк::
::sк:: - avatar
+ 1
But sk <a> tag is also an inline element which hasn't to be empty. So we can't say that inline elements has to be empty.
24th Mar 2019, 6:14 AM
Laksheya
Laksheya - avatar
+ 1
sk I know what you are trying to say but if we took the concept that block level elements starts in new line then <br> must also be a block level element. But still confused why it is not a block level element?
24th Mar 2019, 8:15 AM
Laksheya
Laksheya - avatar