HTML and CSS Reference
Q: So, the only purpose of <br> is to insert a
A: Right; the only place the browser typically inserts
breaks in your content is when you start a new block
element (like <p>, <h1>, and so on). If you want to insert a
linebreak into your text, then you use the <br> element.
Q: Why is <br> called an “void” element?
A: Because it has no content, as in
element = opening tag + content + closing tag. So, it's void
because there's no content and no closing tag. Think like
the “void of space”; there's nothing there, it's empty.
Q: I still don't get it. Explain why the
<br> element is “void”?
A: Think about an element like <h1> (or <p> or <a>).
The whole point of the element is to mark up some content,
A: No. There are two types of elements in the world:
normal elements, like <p>, <h1>, and <a>, and void
elements, like <br> and <img>. You don't switch back
and forth between the two. For instance, if you just typed
<a href=“mypage.html”>, that's an opening tag without
content or a closing tag (not good). If you write
<a href=“mypage.html”></a>, that's an empty element and
is perfectly fine, but isn't very useful in your page!
Q: I've seen pages not with <br>, but with <br />.
What does that mean?
A: It means exactly the same thing. The syntax used
in <br /> is a more strict syntax that works with XHTML.
Wheneven you see <br />, just think <br>, and unless
you're planning on writing pages compliant with XHTML
(see the appendix for more information on XHTML), you
should just use <br> in your HTML.
Elements that don't have
any content by design
are called void elements.
When you need to use a
void element, like <br>
or <img>, you only use
an opening tag. This is
a convenient shorthand
that reduces the amount of
markup in your HTML.
<h1>Don't wait, order now</h1>
With the <br> element, the point is just to insert a linebreak
into your HTML. There is no content you are trying to mark
up. We don't need all the extra brackets and markup, so
we just shorten it into a more convenient form. If you're
thinking “void” is kind of a weird name, you're right: it
comes from computer science and means “no value.”
Q: Are there any other void elements? I think
<img> must be a void element, too, right?
A: Yes, there are a couple of them. You've already
seen us use the <img> element, and we'll be getting to the
details of this element soon.
Q: Can I make any element void? For instance, if I
have a link, and don't want to give it any content, can I
just write <a href=“mypage.html”> instead?