HTML Attributes:

HTML attributes are a additional information about the HTML element. It is a name value pairs like name="value". Attributes is always place inside start tag of the HTML element.

HTML Attributes has been put inside start tag of an HTML element.Do not place HTML attribute inside closing tag of any HTML element.

The href Attribute

The <a> tag has a href attribute that contains the URL of the connected web page.

    
    <a href="https://sudhakarinfotech.com/shop">Visit sudhakarinfotech</a>
   

Example

Source Code

          <a href="https://sudhakarinfotech.com/shop" title="visit sudhakarinfotech">Visit sudhakarinfotech</a>
        
Try it now

Note: The HTML hyperlink element has href and title attribute. The href attribute of the HTML element is used to link the path of another web page while the title describes the web page.

The src Attribute Of An Image

The <img> tag is basically used to show the images.It has src attribute that specifies the path URL of the displaying image.

    
    <img src="URL of the image i.e relative or absolute path" >
   

Example

Source Code

          <img src="https://picsum.photos/200/300" alt="External Image">
        
Try it now

Note:The HTML element <img> has an src attribute that is used for providing a path of the image.

Image Attribute:Width & Height

The is also consists of width and height attributes that specify the width and height of the image respectively.

    
    <img src="URL of the image i.e relative or absolute path"  width=" width of the image" height=" height of the image">
   

Source Code

          <img src="https://picsum.photos/200/300" width="400" height="400">
        
Try it now

Note: The HTML element has a width and height attribute that is used to provide the width and height of the image.

The alt Attribute Of Image

The <img> has attribute alt that is very useful during any path error of the image because it displays alt message when the image does not display on the screen due to server error.

    
   <img src=" URL of the image i.e relative or absolute path" alt=" Title about image">
   

Example

Source Code

          <img src="https://picsum.photos/200/300" width="400" height="400" alt="This is an external image.">
        
Try it now

Note:The HTML <img> element has an alt attribute that is used to provide additional information about the image and it displays on the screen whenever the image file path is not loaded by the browser.

Style Attribute

The style attribute is used to add styles to an HTML element,such as font,size,color ,etc.

Example

Source Code

          <p style="color:green; font-size:18px; text-align:center;">This is a red paragraph.</p>
        
Try it now

Note:The HTML element <style> is used for writing inline CSS rule.

The id Attribute

The id attribute provides unique identification of the HTML element hence it is very easy to select this element using CSS or JavaScript.

Source Code

          #main_heading_text {
  color: white;
  background-color: green;
  padding: 10px;
  font-size: 16px;
}
        
Try it now

Note:The id attribute of an HTML element is unique and the CSS rule regarding the id attribute is only applicable to a single element of an HTML document.

Class Attributes

The class attribute is also used to identify the element but it is not unique since one class value can be assigned to other elements too.

Source Code

          .flower__text {
  color: white;
  background-color: pink;
  padding: 10px;
  font-size: 16px;
  text-align: center;
}
        
Try it now

Note: The class attribute of an HTML element is used for providing CSS rules to more than one HTML element.

Online Test / Quiz

Web Tutorials

HTML Attributes
Html Tutorial HTML
Javascript Tutorial JAVASCRIPT
Css Tutorial CSS
Bootstrap 5 Tutorial BOOTSTRAP 5
Bootstrap 4 Tutorial BOOTSTRAP 4