What is HTML attributes?
Attributes provide extra information about the tags. It always comes in pair i.e. (atribute_name=”value”). We always separate The attribute name and value by “=”.
Let us master all the important attributes-
1. href Attribute
We use <a> tag to define hyperlink, between pages images and more. It is a most used element in the href attribute which specifies the direction of the links.
href="https://www.TutorialBrain.com" is always recommended instead of -
You can also place a single quote if you do not want to use a double quote.
If the value itself has single quotes, then you should use double quotes to surround it.
If the value itself has double quotes, then you should use double quotes to surround it.
3. alt Attribute
The alt attribute provides the alternative text in case, the user is not able to view an image in the website.
If the website has an image, then the 2 most important reasons for images not been shown are –
- The name of the image or the format of the image mentioned in the website is wrong.
- The path of the image is wrong.
If you do not surround the value in your alt attribute as below, then you will get an unwanted result.
Here, instead of showing 'Tulips abc' as output, the result will be 'Tulips'.
3. id Attribute
Id attribute is a way to group some elements and apply a particular style to it. id Name must be unique within the HTML document.
4. class Attribute
The class attribute is a way to group some elements and apply a particular style to it. It is similar to id but the main difference is that id must be unique in an HTML document while classes can have duplicate names.
5. style Attribute
The style attribute sets the style of the HTML document.
6. lang Attribute
The lang Attributes specifies the language used in a particular document.
lang-en – It sets the language as English.
7. dir Attribute
The dir attributes help the browser to flow text in a particular direction like left and right direction.
8. width and height Attribute
Using width and height attribute you can set a size.
9. title Attribute
Title attribute displays the title of the content when you mouse over the content.
Mouse over me to see the title
Interview Question & Answer
Attributes provide extra information about the tags. It always comes in pair i.e. (attribute_name=”value”). We always separate the attribute name and value by “=”.
Here, src and href are attributes.
No, we can use hyperlinks on text and images both. The HTML anchor tag defines a hyperlink(href) that links one page to another page.
To create hyperlinks or links that connect to another web page, we use the “href” attribute.