HTML <br> Tag โ Line Break
๐ Introduction
The <br> tag is used to create a line break in HTML.
It forces the text to move to a new line, without starting a new paragraph.
Unlike most HTML tags, <br> is a self-closing tag (it does not need a closing tag).
๐งฑ Syntax
<br />
or (HTML5 style):
<br />
๐ก Example
<!DOCTYPE html>
<html>
<head>
<title>BR Example</title>
</head>
<body>
<p>Hello<br />World</p>
</body>
</html>
๐ฅ๏ธ Output Explanation
The browser will display:
Hello
World
โ The <br> forces "World" to move to the next line
๐ฏ When to Use <br>
Use <br> for:
- Poem lines
- Addresses
- Simple line spacing inside text
Example:
<p>
Ahmed Khaldi<br />
Algeria<br />
Web Developer
</p>
โ ๏ธ Important Warning
๐ <br> is NOT for layout or spacing!
โ Wrong usage:
<br /><br /><br />
โ This is bad practice because:
- It breaks structure
- Makes code messy
- Should be replaced with CSS
๐ก Better Alternative (Recommended)
Instead of using multiple <br>, use CSS:
<p style="margin-bottom: 20px;">Hello</p>
<p>Hello again</p>
โ Cleaner โ Professional โ More control
๐ซ Common Mistakes
- Using
<br>for spacing โ - Overusing
<br><br>โ - Thinking it creates paragraphs โ
๐งช Mini Exercise
Create a page that shows:
- Your name
- Your country
- Your job or goal
๐ Each on a new line using <br> inside a single <p>