HTML Attribute
SyntaxExampleTest it NowOutput: Explanation of above example: Test it NowIn the above statement, we have used paragraph tags in which we have applied style attribute. This attribute is used for applying CSS property on any HTML element. It provides height to paragraph element of 50px and turns it colour to blue. In the above statement we have again used style attribute in paragraph tag, which turns its colour red. Note: There are some commonly used attributes are given below, and the complete list and explanation of all attributes are given in HTML attributes List.The title attribute in HTMLDescription: The title attribute is used as text tooltip in most of the browsers. It display its text when user move the cursor over a link or any text. You can use it with any text or link to show the description about that link or text. In our example, we are taking this with paragraph tag and heading tag. ExampleWith <h1> tag: Test it NowWith <p> tag: Test it NowCode: Test it NowOutput: The href attribute in HTMLDescription: The href attribute is the main attribute of <a> anchor tag. This attribute gives the link address which is specified in that link. The href attribute provides the hyperlink, and if it is blank, then it will remain in same page. ExampleWith link address: Test it NowWithout link address: Test it NowThe src AttributeThe src attribute is one of the important and required attribute of <img> element. It is source for the image which is required to display on browser. This attribute can contain image in same directory or another directory. The image name or source should be correct else browser will not display the image. ExampleTest it NowNote: The above example also have height and width attribute, which define the height and width of image on web page.Output: Quotes: single quotes or double quotes?In this chapter you have seen that, we have used attribute with double quotes, but some people might use single quotes in HTML. So use of single quotes with HTML attribute, is also allowed. The following both statements are absolutely fine. Test it NowIN HTML5, you can also omit use of quotes around attribute values. Test it NowNext TopicHTML Elements |