HTML Element Attribute
In HTML every element/tag may have or not attributes. There are some common attributes that can be used with every tag element. But some attributes are specific to particular element. These attribute values provide additional information to the browser about DOM element. Attributes are always written within starting tag.
A common attribute of HTML tags is style we can use it with every tag.
Syntax of HTML attribute
HTML attributes are used with assignment operator. Attribute name is used as LValue and value of the attribute is assigned as RValue. All string type attribute values are written inside single or double quote.
Rules for Attributes
- There are some common rules that follow to use in tags.
- Attributes are used only one time.
- Attributes are place in start tag.
- Attributes values are written in double quotes.
- More than one attributes are used separated by space.
HTML common Attributes
The common attributes that are used in every tags are.
Style attribute
Style attribute can be used inside element starting tag for override the default style of HTML tag. This attribute is commonly known as inline style.
inline style is not preferable for better SEO.
Title Attribute
Title attribute is used in HTML5 for displaying tooltip if the element. Tooltip is small hover text that is displayed over the element. Tooltip text is written in double quotes.
Language Attribute
HTML lang attribute is used inside HTML tag. It is used to define language of the webpage. The default value of lang attribute is en. We can also use lang="en-US". It is good practice to always use lang attribute in each and every HTML document.
Image Attributes
Img tag have multiple attributes. That specify dimension, source and style of image. Some of the image element attributes are.
- Src
- Width
- Height
- Title
- Style
- Class
- Id
- Alt
Img Src Attribute
Image source attribute is used to specify path to the image that will display inside img tag. This src attribute may assign absolute or relative path to the source image.It is recommended to use relative path for assets.
Alt Attribute
Image alt attribute is important attribute that is helpful for web browser to identity which image is going to be load. In some cases images cannot be load due to some network or technical issue. Then alt value will be displayed in respect of image. It is considered a good practice to use atl attribute inside every img tag.
Anchor tag Attributes
Anchor tag is used to link one page to another webpage from the same or other website. Some commonly used anchor tag attributes are.
- href
- _target