HTML Elements for Basic Text

As you learned in Chapter 2, you need to know two things about every new element you meet. To use an element correctly, you need to answer these two questions:

  • Is it a container element or a standalone element?

  • Is it a block element or an inline element?

The first question tells you something about the syntax you use when you add an element to a document. Container elements (like the <b> element that boldfaces text) require a start and end tag, with the content sandwiched in between. Standalone elements (like the <img> element that inserts an image into a page) use a single, all-in-one tag. If standalone elements need additional information, like the location of an image file, you supply it using attributes.

The second question tells you something about where you can place an element. Block elements (like the <p> element) go inside the main <body> element or within other block elements of a page. When you start building the overall structure of your page, you always begin with block elements. Inline elements (like the <img> element) have to go inside block elements. Inline elements don’t make sense when they’re on their own, floating free of any container.

Tip

To quickly check whether an element is a container or standalone element and to see if it’s a block or inline element, check the HTML reference in Appendix A.

Block elements also have an effect on the spacing of your content. Essentially, each block element defines a chunk of content. When you end a block ...

Get Creating a Website: The Missing Manual, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.