HTML Attributes

Attributes help us providing additional information about HTML elements. This information is used by the browser in rendering and a complete webpage is generated.  Almost all HTML elements accept attributes. Attributes are always placed in the starting tag of the element with the name and value of attributes. 

For example <h1 id="heading">This is h1 heading</h1>, here id is the attribute and it's value is heading. There are mainly two types of attributes available.

  1. Core attributes
  2. Tag specific attributes

Core Attributes

These attributes are used in almost all HTML tags, all these attributes have different functions.  We have a separate unit for each attribute, but for now, we will note down the application and use case of each attribute in short. 
id: It is used to identify the unique element in a web page. 
title: This attribute gives suggestion on mouse hover in a tooltip. 
class: This is used to attach class from syle to related element. 
style: This helps in giving element level custom style. 

Tag specific attributes

These attributes are required for some HTML tags to complete its function.  For example, if we want to place the image we need to pass the path of the image file. We use src to pass file path. <img src="path/to/file.png"/>. Similarly, for paragraph tag, we can pass align attributes value as mentioned below.   <p align = "left">Now it is left aligned</p>