<?xml version="1.0" encoding="utf-8"?>

HTML is the foundation of web development, providing the essential components that structure and present content on websites. Just as any language has its basic building blocks, HTML has its own set of essential elements that form the backbone of web pages.

HTML elements serve specific purposes and play a vital role in creating well-structured and semantically meaningful web pages. From headings and paragraphs to images and links, each element has its own syntax and attributes that define its behavior and appearance. Understanding these elements and their usage is crucial for developing web pages that are both functional and visually appealing.

Exercise #1

HTML element

The HTML element is as simple as ABC. Most HTML elements start from the start tag and end with the end tag, including only the content between those tags.

Here's an example of the HTML element:

<h1>My First Heading</h1>

However, some elements are self-sufficient enough and don't need the end tag.

Don't forget to use open and close angle brackets and omit spacing inside and between each tag.

Exercise #2

End tag

Different resources call it the "end" or "closing" tag, which is fair as it ends the HTML element. The only distinction between the end tag and the start tag is a forward slash after the first bracket. Ensure you don't have any spacing in between brackets, tag name, and forward slash.

Exercise #3

Tags vs. elements

Technically, an HTML element is the collection of a start tag, its attributes, an end tag, and everything in between. However, in common usage, the terms "HTML element" and "HTML tag" are interchangeable, so when we are talking about tags, we mean elements and vice versa.

Exercise #4

Start tag

The start tag, aka opening tag, is the one that opens the HTML element. It consists of opening and closing angle brackets and the tag name between them. White space is a core part of visual design, but don't change spacing inside tags — they should be as compressed as passengers on a crowded bus.

Exercise #5

Element content

The HTML element content is everything that goes between start and end tags. If it's a heading<h1>Hello, World!</h1> — the text "Hello, World!" is the content, and users will see it as the main headline on a page. However, some parts of the element content can stay invisible to viewers. For example, if it's a <title> element, it appears only on a browser tab bar and in search results.

Exercise #6

Empty HTML element

Empty HTML elements, also known as void elements, are unique because they don't have content between an opening and closing tag. Instead, they perform specific functions or display particular attributes on the page.

Common examples include the <img> tag for images, the <br> tag for line breaks, and the <input> tag for form fields. Since there's no content to wrap, these elements are self-closing and don't require a separate closing tag.

Utilizing empty elements correctly can enhance the structure and readability of your code.

Exercise #7

The <br> tag for line breaks

If you're writing a poem or an address on your webpage, you might need to break text into multiple lines. Here comes the HTML <br> element. It produces a line break, and after the <br>, each line starts with a capital letter. Keep in mind that the <br> element is an empty one without a closing tag.

Exercise #8

Block-level elements

Block-level elements create a rectangular box that takes up the full width of their container. They always start on a new line and push whatever comes next to the next line too.

Some common block-level elements are:

  • <p> for paragraphs
  • <h1> to <h6> for headings
  • <div> for grouping content

These elements help structure the layout by breaking the content into blocks.

Exercise #9

Inline-level elements

Inline-level elements don't break the flow of text. They stay within the same line and only take up as much space as the content inside them. They don’t start on a new line. For example, <b> makes text bold and <i> makes it italic. But they don’t push the text to a new line. The rest of the content keeps flowing around them.

In contrast, block-level elements (like <div> or <p>) always start on a new line and usually take up the full width of the parent. They break the text into chunks. Inline elements don’t. They just change how a part of the line looks or behaves.

Exercise #10

Don't miss slashes

In HTML, using slashes when closing tags is crucial for consistent and proper rendering. Missing a slash can disrupt the structure, leading to unexpected visuals. It also ensures compatibility across different browsers, as inconsistencies in coding might cause your content to appear differently.

Adherence to standards like XHTML requires using slashes, and maintaining the code's integrity and readability. Failing to include a slash where needed can result in errors and affect the overall professionalism of your code. In short, this small detail, although it might seem minor, plays a vital role in web development, contributing to a smooth and consistent user experience.

Exercise #11

Nested HTML element

Just like a Russian nesting doll, some HTML elements can contain other elements, and we describe them as being "nested." In the correct example, the <div> element, which defines a division or a section in an HTML document, contains the <p> element — the paragraph in the text. Make sure to place the nesting elements between the start and end tags of a "parent."

There can be multiple nesting levels, and the relationship between elements and their parent and child elements creates a hierarchy. It's essential to understand this relationship because descendent elements usually inherit behavior and styling from their parent element.

Exercise #12

Don't forget end tags

In most cases, the HTML page looks absolutely fine even if you forget your end tags, but it's better to be safe than sorry. Not closing tags can cause browser incompatibilities and improper page rendering. So as a best practice, close your tags and make your website compatible with any browser.

Complete this lesson and move one step closer to your course certificate