Here are some commonly used HTML attributes and their uses:
|alt||This attribute is used in the <img> tag. If the image does not appear, the text of this attribute is displayed in the browser as an alternative.|
|charset||This attribute is used in the <meta> tag. That is, it is used to determine the character encoding.|
|disabled||This attribute is used in the <input> tag. That is, this attribute is used to disable a certain input element.|
|href||This attribute is used in the <a> tag. That is, it is used to set the URL of a link.|
|lang||Contains information about the language of the document.|
|id||Sets a unique name for an element.|
|src||Sets the source of an image or script.|
|style||It is used to style an element online.|
|title||It is used to attach additional information about an element. The content of the title attribute is displayed as a tooltip with the mouse over the title element.|
Visit the HTML Attributes Reference page to see a list of all attributes of HTML elements and their usage.
If the image does not appear, the alt attribute is used to set a text as an alternative to the image.
The charset attribute is used in the <meta> tag to determine the character encoding of the document.
Charset="utf-8" is used to display correctly in any language browser other than English.
The URLs in the HTML <a>, <area>, <base>, <link> tags are set by the href attribute.
The lang attribute is used in the <html> tag to set the language of the document.
The src attribute is used to add source files for HTML <img> and <script> tags.
Hovering the mouse over an element uses a title attribute to display text in tooltip format.
Always write attributes in lower case
It is not mandatory to write the name of the attribute in lowercase in HTML (5).
The charset attribute can be written in capital letters or lowercase letters. E.g. Charset or CHARSET.
However, W3C recommends that HTML attributes are always written in lower case.
Use quotation marks in the value of attributes
Writing in the value quotation (" ") of the attribute in HTML (5) is not mandatory.
For example, href attributes can be written without quotations (" ") as described above:
But sometimes it is necessary to use quotations (" "). For example, in the following example, the value of the title attribute has a space, so it will not work properly.
Single (' ') or double (" ") quotations
Double (" ") quotations are commonly used to write the value of HTML attributes. However, we can also use single (' ') quotations.
However, single/double quotations are used in the value of the attribute as per the situation and as required.
Or use the opposite way.
Summary of the chapter
All HTML elements can have attributes.
the alt attribute provides the text for readers.
href determines the URL of the attribute link.
lang Sets the language of the attribute document.
The src attribute determines the source url.
The title attribute provides information in the form of a "tool-tip".