The <br> tag is an essential element in HTML. It serves the purpose of creating line breaks within text content. This tag proves to be particularly handy when individuals need to format poems, addresses, or display code snippets.
The <br> tag is classified as an empty or self-closing tag, which means there is no requirement to include a closing tag for it. However, in XHTML coding standards, it is necessary to properly close the <br> tag.
An illustration will help clarify the purpose of the br tag. Let's explore the functionality of the br tag through the two examples presented below:
Illustrative example 1: The following example demonstrates the implementation of the <br> tag within a poem to create a line break.
<!Doctype Html>
<Html>
<Head>
<Title>
Example: how to use <br> tag in poem
</Title>
</Head>
<Body bgcolor="red">
Hello User!...
<center>
Poem
<br> <br>
<font color="blue">
Hold fast to dreams <br>
For if dreams die <br>
Life is a broken-winged bird <br>
That cannot fly. <br>
Hold fast to dreams <br>
For when dreams go <br>
Life is a barren field <br>
Frozen with snow. <br>
</center>
</Body>
</Html>
The result of the HTML code above can be viewed in the screenshot below:
Illustrative Example: Here is a demonstration illustrating the implementation of the <br> tag within code snippets to indicate a line break.
<!Doctype Html>
<Html>
<Head>
<Title>
Example: how to use <br> tag in code sample
</Title>
</Head>
<Body bgcolor="orange">
Hello User!...
<center>
Code for add two number
<br> <br>
<font color=" blue">
int main() <br>
{ <br>
int x, y, z; <br>
printf("Enter two numbers to add\n"); <br>
scanf("%d%d", &x, &y);<br>
printf("Sum of the numbers = %d\n", z);<br>
}<br>
</center>
</Body>
</Html>
The HTML code displayed above generates the output visible in the screenshot below: