Where to use <br>, <br/> and <br /> ?
The <br> tag in HTML is used to break the line. In HTML, <br> is preferred, but we can use <br/> and <br /> as well. <br> is an empty tag, so we don’t need to close this tag. We can use either <br> or </br> to break line, both are allowed (but not both(<br> </br>) because it will give us two-line break).
In XHTML, <br /> is preferred, but we can use <br/> or <br></br> since XML doesn’t allow leaving tags open.. The outdated browsers parse XHTML as HTML and failed with <br/>.
Note: XHTML is case-sensitive and HTML is not.
How do I use <br>: we can just place <br> whatever position we want a line break.
HTML
<!DOCTYPE html> < html > < head > < title > br example </ title > </ head > < body > < p > Hi My name is Kapil. < br > I am 23 year old.</ p > </ body > </ html > |
Output:
As we can see from the above code the <br> tag breaking the line and the next statement printing in a new line.
How do I use </br>: we can just place </br> whatever position we want a line break same as <br> tag.
HTML
<!DOCTYPE html> < html > < head > < title > br example </ title > </ head > < body > < p > Hi My name is Kapil. </ br > I am 23 year old.</ p > </ body > </ html > |
Output:
As we can see from the above code it is giving the same output as <br> tag giving.
Conclusion: The <br> and </br> tag can be used alternatively but if we use both together then we will get two line breaks, one for <br> and other for </br>.
Example 1: Using both <br> and </br> (It gives two line breaks)
HTML
<!DOCTYPE html> < html > < head > < title > br example </ title > </ head > < body > < p > Hi My name is Kapil. < br ></ br > I am 23 year old.</ p > </ body > </ html > |
Output:
Example 2: <br/> Used to break line in XHTML.
HTML
<!DOCTYPE html> < html > < head > < title > br example </ title > </ head > < body > < p > Hi My name is Kapil. < br /> I am 23 year old.</ p > </ body > </ html > |
Output:
Example 3
HTML
<? xml version = "1.0" encoding = "UTF-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" xml:lang = "en" lang = "en" > < body > < p > This is Example of using < br /> tag. < br /> This text will come in new line.</ p > </ body > </ html > |
Output:
Please Login to comment...