HTML Attribute

Attributes are used to define the more particular information within an element. They attribute generally come in name, value pairs, (name=“value”). Attributes can also be used to  resize images, change the size of font, colour of font and the text.

<tag name  attribute_name= "attribute_value"> content </ tag name>  
<p style="color: red">content</p> 

An HTML attributes provide extra information about HTML elements.

  • All HTML elements can have attributes
  • Attributes provide extra information about elements
  • Attributes are always define in the start tag
  • Attributes generally come in name/value pairs like: name="value"

An attribute is used to specify the characteristics of an HTML element which is placed inside the element's opening tag. All attributes are come into two parts − a name and a value

  • The name is the property which you want to set. For example, the paragraph <h1> element in the example bring an attribute whose name is align, which you can use to show the alignment of paragraph on the page.

  • The value is property which you want to be set and always put within double quotations or may be single quotations. Now we discussed the example that shows the possible values of align attribute: left, center and right.

HTML Attribute names and attribute values are case-insensitive and World Wide Web Consortium (W3C) recommends lowercase attributes values in their HTML 4 recommendation. 

Example

<!DOCTYPE html> 
<html>
 
   <head> 
      <title>HTML Align Attribute  Example Code</title> 
   </head>
	
   <body> 
      <h1 align = "left">This is left aligned Heading</h1> 
      <h1 align = "center">This is center aligned Heading</h1> 
      <h1 align = "right">This is right aligned Heading</h1> 
   </body>
	
</html>
  Try it Yourself

OUTPUT

This is left aligned Heading

This is center aligned Heading

This is right aligned Heading

The href Attribute

in the HTML <a> tag defines a hyperlink and it's contain the href attribute which contain the url of the page which you want to follow with the html document.

Example

<!DOCTYPE html>
<html>
  <head>
    <title>The href Attribute Example</title>
  </head>
<body>

<h2>The href Attribute Example Code</h2>

<p>in the HTML <a> tag defines a hyperlink</p>

<a href="https://exampot.com">Hyperlink of TestHike</a>

</body>
</html>
  Try it Yourself