04.06.2013 Views

Head First HTML with CSS

Head First HTML with CSS

Head First HTML with CSS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

empty elements have no closing tag<br />

100 Chapter 3<br />

In Chapter 1 we said that<br />

an element is an opening tag +<br />

content + closing tag. So how is<br />

an element? It doesn’t have<br />

any content, and it doesn’t even<br />

have a closing tag.<br />

Exactly, it doesn’t have any content.<br />

The element is an element that doesn’t have any content. Why? Because it’s just<br />

meant to be a linebreak, nothing else. So, when an element doesn’t have any real content<br />

by design, we just use a shorthand to represent the element and it ends up looking like<br />

. After all, if we didn’t have this shorthand, you’d be writing every<br />

time you needed a linebreak, and how much sense does that make?<br />

isn’t the only element like this; there are others, and we have a name for them:<br />

empty elements. In fact, we’ve already seen another empty element, the element.<br />

We’ll be coming back to look at the element in detail in a couple chapters.<br />

Keep in mind, the reason for the shorthand isn’t laziness so much as it is efficiency. It’s<br />

more efficient to represent empty elements this way (efficient in typing, in the number<br />

of characters that end up in a page, and so on). In fact, after reading <strong>HTML</strong> for a while,<br />

you’ll find that it is easier on your eyes too.<br />

Here’s the opening tag.<br />

Content? Hmm, the whole point of<br />

this element is to insert a linebreak.<br />

There’s really no content.<br />

<br />

I’m half the<br />

element I used to<br />

be... (sniff sniff).<br />

<br />

<br />

Here’s the closing tag.<br />

Okay, typing this in is REALLY silly.<br />

We know there’s never going to be any<br />

content between those tags.<br />

Yeah, if we just type this<br />

then it really represents<br />

the same thing.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!