4

I am trying to understand why browser behaves like this.

I have following text in html document.

<html>
<body>
This is Sample Text. <B/>Text after empty bold tag.
</body>
</html>

If I view this document in browser, it is displayed as shown below.

This is Sample Text. Text after empty bold tag.

Why is this happening? Afterall, I did not mark any text as bold.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sambhaji
  • 990
  • 5
  • 19
  • 31

3 Answers3

2

You need to write valid html code for this to work correctly with opening and closing tags. So you would need to write an opening tag (<B>) before the text you want in bold and a closing tag () after the text.

<html>
    <body>
        <B>This is Sample Text.</B>Text after empty bold tag.
    </body>
</html>

Notice that in your example you are using <B/> which is neither a valid opening or closing tag but which may be interpreted as an opening tag in certain browsers.

Nachshon Schwartz
  • 15,289
  • 20
  • 59
  • 98
1

<b/> is not a closing tag. </b> is a closing tag. <b/> is an opening tag with a useless slash in it.

Blazemonger
  • 90,923
  • 26
  • 142
  • 180
0

I think it behaves like the self-closing tag <br/> which applies the desired effect after the tag definition.

Take a look at this topic regarding self-closing tags: What are all the valid self-closing elements in XHTML (as implemented by the major browsers)?

I think this could also depend on the browser you're using. If you're trying this in firefox or chrome, they are known to try and correct you "bad coding", so it might be thinking it's a typo and trying to correct it the best way it can.

Community
  • 1
  • 1
José P. Airosa
  • 368
  • 1
  • 2
  • 11