Attributes
Published by
sanya sanya
HTML attributes provide additional functionalities to tags and information about the respective HTML element.
Some Important HTML Attributes
The href Attribute
The <a> tag defines a hyperlink. The href attribute specifies the URL of the page the link goes to:
Example:
<a href="https://www.codingblocks.com"> Coding Blocks </a>
The src Attribute
The <img> tag is used to embed an image in an HTML page. The src attribute specifies the path to the image to be displayed:
There are two ways to specify the URL in the src attribute:
Absolute URL -Links to an external image that is hosted on another website.
Relative URL -Links to an image that is hosted within the website. Here, the URL does not include the domain name. If the URL begins without a slash, it will be relative to the current page. Example: src="img.jpg". If the URL begins with a slash, it will be relative to the domain.
The width and height Attributes
The <img> tag should also contain the width and height attributes, which specify the width and height of the image (in pixels):
Example
<img src="img.jpg" width="500" height="600">
The alt Attribute
The required alt attribute for the <img> tag specifies an alternate text for an image if the image for some reason cannot be displayed. This can be due to a slow connection, an error in the src attribute, or if the user uses a screen reader.
Example:
<img src="img.jpg" alt="This text will be shown if image does not load">
The style Attribute
The style attribute is used to add styles to an element, such as color, font, size, and more.
Example:
<p style="color:red;">This is a red paragraph.</p>
The title Attribute
The title attribute is used to give or define some extra information about an element.
The value of the title attribute will be displayed as a tooltip (in a box) when you mouse over the element:
Example:
<p title="I'm a tooltip">This is a paragraph.</p>
Common Attributes
Some common Attributes that can be used with almost every HTML element are:
-
The id attributeIt provides a document-wide unique identifier for an element. This can be used as a CSS selector to provide presentational properties, by browsers to focus attention on a specific element, or by scripts to alter the contents or presentation of an element.
-
The class attributeIt provides a way of classifying similar elements. Multiple class names can be added by separating them with spaces. Additionally, authors of style sheets can construct selectors that match elements by class for styling purposes. The class name can be used by CSS and JavaScript to perform certain tasks for elements with the specified class name.
Library
WEB DEVELOPMENT
Basic
HTML - Hyper Text Markup Language
HTML: Hyper Text Markup Language
Getting Started with HTML
Working with Tags
HTML Tags
Attributes
Block & Inline Elements , HTML Entities
HTML Links
HTML Forms
Tables In HTML
HTML SEMANTICS
CSS - Cascading Style Sheets
JavaScript
Frontend
Backend
Interview Questions
FAANG QUESTIONS
On this page
Some Important HTML Attributes
The href Attribute
The src Attribute
The width and height Attributes
The alt Attribute
The style Attribute
The title Attribute
Common Attributes

