← Web basics: HTML, CSS and JavaScript
Elements, tags and attributes
How HTML pieces open, close, nest and carry extra information.
HTML is made of elements. Most elements have an opening tag like <p>, some content, and a closing tag with a slash like </p>. Elements can go inside other elements (nesting), but they must close in the reverse order they opened, like boxes inside boxes. Opening tags can also carry attributes: extra information written as name="value", such as the address of a link.
<p id="intro">Our café serves <strong>fresh</strong> juice.</p>
<img src="juice.jpg" alt="A glass of orange juice">
<br><p> ... </p> is a paragraph element. Inside it, <strong> makes one word important (shown bold). id="intro" is an attribute giving the paragraph a name. <img> and <br> are "empty" elements: they have no content, so they have no closing tag.
Wrong nesting: <p><strong>Hi</p></strong>. Right nesting: <p><strong>Hi</strong></p>. The element opened last closes first.
Tag names are not case-sensitive, but everyone writes them in lowercase. Attribute values go in quotes.