HTML #3 - HTML Attributes clear explanation and uses


Hello friends, welcome to the another tutorial of HTML Programming Series. In this tutorial, we will know about the HTML attributes, its uses and some important facts about the uses of HTML Attributes. So friends, let's begin..

ATTRIBUTES

Attributes is used in HTML to define tags i.e. providing additional information about any tags. Almost all tags in HTML has attributes. It always comes in name="value" pair. It is always written in the starting tag to customize any element behaviour. The "name" means the name of the attributes, that is to be customize and "value" means the value, which is to be set to the attributes.

<img src="home.png"/>
<a href = "https://programminginfinity.blogspot.com/"> Programming Infinity </a>

In the above examples, <img> tag and <a> tag is used for showing image and showing links respectively. In <img> tag, the "src" attribute is used for adding the image path. As it is seen that, it is written in the form "name="value", in which "src" is the name and "home.png" is the value.

NEVER FORGET QUOTES

  1. <p title=Programming Infinity > Hi </p>
  2. <p title=ProgrammingInfinty>Error !</p> in another HTML Version exclusive, HTML5.
  3. <p title="Programming Infinity" >Good :)</p> works in all HTML Version.

In the attributes, the value is written within the quotes. It is recommended to use quotes in HTML, whereas in HTML5, it will work without quotes,but in the first example, we had provided a title to a paragraph, which will show when the mouse hover over it. As in the title there is space between the words, so it will not show and will raise a error, as it is not within the quotes, still in HTML5. and in second example, we had not any space between the characters, still it will raise an error in another HTML version except HTML5. So, It is recommended to write the value within the quotes.

SINGLE OR DOUBLE QUOTES

  1. <p title='happy"infinity"oooo'>Single Quotes</p>
  2. <p title="happy'infinity'oooo">Double Quotes</p>
  3. <p title=?happy'infinity'ooo"infinity"ooo?>Unknown Symbol</p> ? = Unknown Symbols.
  4. <p title &quot;happy"infinity"ooo'infinity'ooo&quot;>Entities</p>

In HTML, Generally Double quotes are used, but we can use single quotes also. If we see the first example, then we can see that the value of the "title" attribute for the paragraph has already double quotes in it, then, In this type of situation, It is advised to use single quotes for the value and vice-versa (example 2). Looking in third example, notice that the title contains single and double quotes in the value, then in this type of situation entities are used. we will know about this in the another tutorial. "&quot;" is an entity for the quotes. use of this can be seen in the fourth example. So, It is recommended by programming infinity to use entities instead of quotes for code to be strictly validated by the web browsers and compilers.

Note:- It is recommended by Programming infinity to use lower case letters for writing HTML Code and in the attributes. Codes of Programming Infinity are also written in lower case.

Comments