When it comes to HTML, understanding the role of Elements and Attributes is crucial.
See previous article: Introduction to HTML, to cover the basics
Elements
The Element serves as the foundation of an HTML document, defining its structure and content. It encompasses the entire document and acts as the root element. The Element is characterized by a start tag <> and an end tag </>. It encapsulates all other elements within a webpage, providing a foundation for organizing content and defining its structure.
<!DOCTYPE html>
<html>
<head>
<title>The title</title>
</head>
<body>
<h1> My Website </h1>
<br>
<a href="/"> Go to HomePage </a>
<p> My content </p>
</body>
</html>
Basic properties of Elements
- The structure of an HTML element consists of three essential parts: a start tag <>, the content, and an end tag </>. Example <h1> My Website </h1>.
- Certain HTML elements, do not contain any content. These elements are commonly referred to as empty elements. It is important to note that empty elements do not require an end tag. Example <br> is used for line break or next line.
- <html>: This is the root element of an HTML page. Everything within <html>...</html> is considered part of the HTML document.
- <body>: The element is an essential component for organizing your document, acting as a comprehensive container for all the visual elements that comprise its content. It efficiently manages and structures various elements such as headings, paragraphs, images, hyperlinks, tables, lists, and much more.
- Never skip the end tag. While some HTML elements may still display correctly even if you forget the end tag, it is important to always include it for proper coding and to ensure consistent rendering across different browsers and devices.
Attributes
Attributes further enhance HTML elements by providing additional information or functionality. For example, an attribute like "href" in an anchor tag specifies where a link should navigate when clicked. Similarly, attributes like "src" in an image tag define the source location for an image file.
Basic properties of Attributes
- All HTML elements can have attributes.
- Attributes are always added in the start tag
We will look at common HTML Elements and Attributes in next article.
References: