What are HTML Elements || HTML Attributes || HTML images

3 minute read
0

HTML Elements:- 

HTML elements are the building blocks of an HTML document. An HTML element is defined by a start tag, content, and an end tag (with the exception of some elements that are self-closing).


The start tag is the opening tag that defines the beginning of an element, and it is enclosed in angle brackets (<). The end tag is the closing tag that defines the end of an element, and it is also enclosed in angle brackets but with a forward slash before the element name (</). The content of an element is the text or other elements contained within it.


Here are some examples of HTML elements:


<h1>: Defines a heading.

<p>: Defines a paragraph.

<a>: Defines a hyperlink.

<img>: Defines an image.

<ul>: Defines an unordered list.

<li>: Defines a list item.

<div>: Defines a section of the document.



Some HTML elements are self-closing, meaning they don't have a closing tag. Instead, they have a forward slash before the closing angle bracket of the opening tag. Here's an example of a self-closing element:


<br />: Defines a line break.

HTML elements can also have attributes, which provide additional information about the element. Attributes are included within the opening tag of an element, and they are written in name-value pairs. For example, the a element can have an href attribute that specifies the URL of the hyperlink:

HTML Attributes:-

HTML attributes provide additional information about an HTML element. They are used to modify the behavior, appearance, and other characteristics of an element. Attributes are included in the opening tag of an HTML element and are written in name-value pairs.





Here are some common HTML attributes:


id: Specifies a unique identifier for an element. The value of the id attribute must be unique within the HTML document.


class: Specifies one or more class names for an element. The value of the class attribute can be used to apply CSS styles to multiple elements at once.


style: Specifies inline styles for an element. The value of the style attribute is a set of CSS declarations separated by semicolons.


src: Specifies the URL of an external resource, such as an image or script.


href: Specifies the URL of a hyperlink.


title: Specifies a tooltip or a title for an element.


alt: Specifies alternative text for an image or other non-text element.


Here's an example of an HTML element with attributes:


<a href="https://www.example.com" class="button" id="link1">Click here</a>


In this example, the a element has three attributes: href, class, and id. The href attribute specifies the URL of the hyperlink, the class attribute assigns the button class to the element, and the id attribute assigns the unique identifier link1 to the element.

HTML Images :-

To add an image in HTML, you can use the img tag. The img tag is a self-closing tag, which means it doesn't have a closing tag.

Here's the basic syntax for adding an image in HTML:

<img src="image.jpg" alt="Image description">

In this example, the src attribute specifies the URL or file path of the image file, and the alt attribute provides a textual description of the image. The alt attribute is important for accessibility purposes, as it provides alternative text for visually impaired users who may be using a screen reader.

Here's an example of how to add an image to an HTML document:

<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
</head>
<body>
<h1>Welcome to my website</h1>
<p>Here is an image:</p>
<img src="image.jpg" alt="A beautiful mountain landscape">
</body>
</html>

In this example, the img tag is used to display an image of a mountain landscape. The src attribute specifies the path to the image file, and the alt attribute provides a description of the image.

Note that the src attribute can be a relative or absolute URL, and the image file can be in any format supported by web browsers, such as JPEG, PNG, or GIF

Post a Comment

0Comments
Post a Comment (0)