HTML (HyperText Markup Language) is the basic building block of every web page. It allows developers to structure content using predefined elements that can hold text, images, links, or forms. Attributes are special words used inside opening tags to provide extra information or behavior, such as identifiers, classes, or source URLs.
<p>This is a paragraph</p>.< >, like <div> or </h1>.class="header" or src="image.jpg".id, class, href, src, alt, title.In HTML, everything is built from elements. Each element starts with an opening tag, may contain content, and ends with a closing tag. Attributes are placed inside the opening tag to configure how that element behaves or is identified.
Block-level elements such as <div>, <p>, and <section> stretch to take the full available width and start on a new line. Inline elements such as <span>, <a>, and <img> only take as much width as needed and flow within a line of text. Understanding this difference is essential for layout and design.
Void elements are elements that do not have closing tags and cannot contain any content. Examples include <br>, <hr>, <img>, and <input>. They still can (and often do) use attributes.
Attributes control element behavior and provide additional information. For example, href in an <a> tag sets the destination URL of a link, and src in an <img> tag sets the image source. Without attributes, HTML pages would be far less interactive and customizable.
The following example shows how elements and attributes work together in a simple paragraph and image:
<!-- Paragraph with class and title attribute -->
<p class="intro" title="Introductory text">
Welcome to the world of HTML!
</p>
<!-- Image with src and alt attributes -->
<img src="https://via.placeholder.com/150" alt="Placeholder Image" />
Welcome to the world of HTML!
In the browser, you see the paragraph text and the image. The class="intro" attribute can be used by CSS or JavaScript to style or select the paragraph, while the title attribute shows a tooltip on hover. The image uses src to define its location and alt to describe it for screen readers and when the image cannot load.
id="main".alt text for images to improve accessibility.<header>, <nav>, <main>, and <footer> for better structure and SEO.href for links or src for images and scripts.class and title attribute. Open it in the browser and hover to see the tooltip.<img> with both src and alt attributes. Try changing the URL to see what happens when the image fails to load.<div>, <p>) and inline elements (<span>, <a>) and notice the layout differences.id and another with a class, then write a small CSS file or style block to style them differently.<br> or <hr> and observe that they do not need closing tags.HTML elements provide the structure of a web page, and attributes give those elements additional power and meaning. By understanding how to use elements, distinguish between block and inline behavior, apply global attributes, and work with void elements, you can build rich, well-structured, and accessible web pages. Mastering elements and attributes is a key step toward writing clean, professional HTML.