HTML Attribute

HTML Attribute

Some commonly used HTML attributes and their uses:
Attribute Description
alt This attribute <img>is used in tags. If the image is not displayed, the text of this attribute is displayed in the browser as an alternative.
charset This attribute <meta>is used in tags. That is, it is used to specify the character encoding.
disabled This attribute <input>is used in the tag. That is, this attribute is used to disable a specific input element.
href This attribute <a>is used in the tag. That is, it is used to set the URL of a link.
long Contains information about the language of the document.
id Sets a unique name for an element.
source Sets the source of an image or script.
style It is used to style an element inline.
title It is used to attach additional information about an element. The content of the title attribute is displayed as a tooltip when the mouse is hovered over the element with title .

alt attribute

altThe attribute is used to set a text alternative to the image if the image is not displayed .

Examples
				
					<!DOCTYPE html>
<html>
<head>
 <title>HTML alt attribute</title>
</head>
<body>
 <img decoding="async" src="ql.png" alt="quicklearn3945.com" width="142" height="142">
</body>
</html>
				
			
Output
HTML alt attribute quicklearn3945.com

charset attribute

Attributes are used <meta>within tags to specify the character encoding of the document .charset

To display any language other than English correctly in browsers, charset=”utf-8″ is used.

Examples
				
					<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>HTML charset attribute</title>
</head>
<body>
<p>Charset="utf-8" is used to display any language other than English correctly in browsers.</p>
<p>The Bangla font used in our examples when trying it yourself
If your browser does not support or the Bangla font breaks, you can use charset="utf-8"
to fix the font problem.</p>
</body>
</html>
				
			
Output
HTML charset attribute

Charset="utf-8" is used to display any language other than English correctly in browsers.

The Bangla font used in our examples when trying it yourself If your browser does not support or the Bangla font breaks, you can use charset="utf-8" to fix the font problem.

href attribute

The URL is set via the attribute of the HTML <a><area><base><link>tag .href

Examples
				
					<!DOCTYPE html>
<html>
<head>
<title>HTML href attribute</title>
</head>
<body>
<a href="http://www.quicklearn3945.com">This is a link</a>
</body>
</html>
				
			
Output
HTML href attribute This is a link

lang attribute

Attributes are used <html>within tags to set the language of the document .lang

Examples
				
					<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML lang Attribute</title>
</head>
<body>
<p>The lang attribute is used within the <html> tag to set the language of the document.</p>
</body>
</html>
				
			

src attribute

Attributes are used to add HTML <img>and tag source files.<script>src

Examples
				
					<!DOCTYPE html>
<html>
<head>
<title>HTML src attribute</title>
</head>
<body>

<img loading="lazy" decoding="async" src="../ql .png" width="142" height="142">

</body>
</html>
				
			
Output
HTML Attribute

title attribute

titleThe attribute is used to display text in the form of a tooltip when the mouse hovers over the element .

Examples
				
					<!DOCTYPE html>
<html>
<head>
<title>HTML title attribute</title>
</head>
<body>
<p title="This is a tooltip">When you hover over this paragraph, the
value of the title attribute will be displayed as a tooltip.</p>
</body>
</html>
				
			
Output
HTML title attribute

When you hover over this paragraph, the value of the title attribute will be displayed as a tooltip.

Always write attributes in lowercase.

In HTML(5), attribute names are not required to be written in lowercase.

charsetThe attribute can be written in capital letters or small letters. For example, Charset or CHARSET .

However, the W3C recommends always writing HTML attributes in lowercase.

Using quotation marks in attribute values

In HTML(5), it is not mandatory to enclose attribute values ​​in quotation marks (“”).

hrefFor example, the attribute can be written without quotation marks (“”) as described above:

Examples
				
					<!DOCTYPE html>
<html>
<head>
<title>HTML Attributes</title>
</head>
<body>
<a href=http://www.quicklearn3945.com>This is a link</a>
</body>
</html>
				
			
Output
HTML Attributes This is a link

But sometimes it is necessary to use quotations(“”). For example, in the example below, it will not work properly because the title attribute value has spaces.

Examples
				
					<!DOCTYPE html>
<html>
<head>
<title>HTML Attributes</title>
</head>
<body>
<p title=Quick Learn>If the attribute value contains a space,
you cannot remove the quotation marks ("").</p>
</body>
</html>
				
			
Output
HTML Attributes This is a link

Single(' ') or double(" ") quotations

Double (“”) quotation marks are usually used to write the value of HTML attributes. However, we can also use single (‘ ‘) quotation marks.

However, single/double quotations are used in attribute values ​​according to the situation and need.

				
					<p title='"Quick" Learn'>Quick Learn</p>
				
			

Or we can use it the other way around.

				
					<p title="'Quick' Learn">SAT Academy</p>
				
			

Chapter summary

  1. All HTML elements can have attributes .

  2. altThe attribute provides text for readers.

  3. hrefThe attribute specifies the URL of the link.

  4. langThe attribute sets the language of the document.

  5. srcThe attribute specifies the source url.

  6. srcThe attribute specifies the source url.

HTML Attribute

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *