HTML Attribute
What is Attribute in HTML?
HTML attributes provide additional information approximately HTML elements.
An HTML attribute is a piece of markup language used to alter the behavior or show of an HTML element.
HTML Attributes
Attributes characteristics:
- All HTML element may have attributes
- Attributes offer extra information about element
- Attributes generally come in name/value pairs like: name="value1"
Id Attribute
The id attribute of an HTML tag may be used to uniquely perceive(identify) any element inside an HTML web page.
The href Attribute
The <a> tag defines a hyperlink. The href attribute specifies the URL of the page the link goes to:
<p>Visit the <a href="https://www.example.com">Example Website</a></p>
The src Attribute
The <img> tag is used to embed an image in an HTML web page. The src attribute specifies the path to the image to be displayed:
<img src="example-image.jpg" alt="Example Image">
The width and height Attributes
The <img> tag need to also include the width and height attributes, which specify the width and height of the image (in pixels):
<img src="example.png" alt="Example Image" width="300" height="200">
The style Attribute
The style attribute is used to add styles to an element, along with color, font, size, and extra.
<p style="color: blue; font-size: 18px; text-align: center;">This is a styled paragraph.</p>