HTML - Attributes

Attributes

Attributes provides additional properties inside an HTML element. They are placed inside the opening tag of an HTML element. Attribute consists of two parts and this is how it is written: name="value"

  • name - This specifies the name of the attribute
  • value - This specifies the value of the attribute for the given name

href Attribute

This attribute is used inside link tags: (<a>, <link>, <base>). The value contains the address/location (URL) to be directed to.

note
NOTE:

<a> is called the anchor element. It is used to create a hyperlink to web pages, files, email addresses, locations in the same web page and any other URL.

URL (Uniform Resource Locator): is an address of a specific web page or file on the internet.


title Attribute

This attribute is used add additional information to an element, which displays as a tooltip, when you mouse over the element. The value usually contains texts.

lang Attribute

This attribute specifies the language of the HTML document. The value usually the country code. It is mostly used inside the <html> tag.

src Attribute

This attribute specifies that address or path of a particular file or document. It is often used inside the following tags: <img>, <source>, <script>.

In the example below I used the <img> which is used to place images inside the web page.

tips
TIPS:

href - is Hypertext Reference.
It is used reference information from another page usually an HTML file.
src - is Source Reference.
It is used to add or loaded resources such as images, videos and scripts.


width and height Attribute

The width and height attribute are used to set the width and height of elements.

Case Sensitivity

HTML attributes are not case sensitive. href is the same thing as HREF. But I will advise that you use lowercase at all times for smooth and clean coding.

Single or Double Quotes

Double quotes are commonly used in attributes, but you can also use single quotes.

But in situation where by you have single quotation mark inside the value itself, then use double quotation mark. Vice versa!

ATTRIBUTES TAGS/DESC.
alt

<img>, <input>, <area>

Alternate text when the element fails to display

style

Global

For setting inline style for an element.

target

<a>, <area>, <base>, <form>

Specifies where to open the link file or form submitted.

rel

<a>, <area>, <link>, <form>, <script>

For setting the relationship between the current document and the linked file or document

max

<input>, <progress>, <meter>

Used for setting maximum value

min

<input>, <meter>

Used for setting minimum value

maxlength

<input>, <textarea>

Used for setting maximum number of characters

id

Global Attribute

Used for setting unique identification for an element

class

Global Attribute

Used for setting one or more class identification for more than one element


Attribute References

HTML has a lot of attributes that you can use for various purposes, to see more attributes and what they are being used for, later you can visit Attribute References. But for now, these are the basic ones you will often used most of the time.

ADVERTISEMENTS

LEARNING IS A CONTINOUS PROCESS - PRACTICE MAKES PERFECT