Questions And Answers

More Tutorials

HTML attributes

HTML attributes are special words used inside the opening tag to control the element's behaviour. HTML attributes are a modifier of an HTML element type. An attribute either modifies the default functionality of an element type or provides functionality to certain element types unable to function correctly without them. In HTML syntax, an attribute is added to an HTML start tag.

Several basic attributes types have been recognized, including: required attributes, needed by a particular element type for that element type to function correctly; optional attributes, used to modify the default functionality of an element type; standard attributes, supported by many element types; and event attributes, used to cause element types to specify scripts to be run under specific circumstances.

Some attribute types function differently when used to modify different element types. For example, the attribute name is used by several element types, but has slightly different functions in each.

1. The href attribute

 <a href=""> Content of html page...  </a> 

The Above example show an anchor tag having href attribute:

  • anchor tag defines a hyperlink, which is used to link from one page to another
  • href is a mandatory attribute which indicates the link's destination.

2. The src attribute

 <img src="img.png"> 

The Above example show an image tag having src attribute:

  • src attribute is to specify a URI for an external file or resource.
  • HTML src attribute supports frame, iframe, img, input and script elements.

3. The Width & Height attribute

 <img src="img.png" width="500" height="600"> 

The Above example show an Image tag having 3 attribute:

  • src is a mandatory attribute which tells the browser the path of the image.
  • width is an optional attribute to tell the browser about the width size of the image.
  • height is an optional attribute to tell the browser about the heightsize of the image.

4. The Style attribute

 <p style="color:red"> This is a red paragraph </p>

The Above example show an paragraph tag having style attribute:

  • The style attribute specifies an inline style for an element.
  • The style attribute can be used on any HTML element.


In this page (written and validated by ) you learned about HTML Attribute . What's Next? If you are interested in completing HTML tutorial, your next topic will be learning about: HTML Heading.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.