HTML Attributes

 HTML attributes provide additional information about HTML elements.

 

The href Attribute

The <a> tag defines a hyperlink. The href attribute specifies the URL of the page the link goes to:

Example

<a href="https://mybcaclassnotes.blogspot.com">Visit </a>
 
The src Attribute

The <img> tag is used to embed an image in an HTML page. The src attribute specifies the path to the image to be displayed:

<img src="india.jpg" />
 
There are two ways to specify the URL in the src attribute: 

 1. Absolute URL

An absolute URL contains the entire address from the protocol (HTTPS) to the domain name (www.example.com) and includes the location within your website in your folder system (/foldernameA or /foldernameB) names within the URL.

Basically, it's the full URL of the page that you link to.

An example of an absolute URL is:

<a href = http://www.example.com/xyz.html

2. Relative URL

The relative URL, on the other hand, does not use the full web address and only contains the location following the domain. It assumes that the link you add is on the same site and is part of the same root domain.

The relative path starts with the forward slash and leads the browser to stay within the current site.

An example of a relative URL is:

<a href = "/xyz.html">

 

The width and height Attributes

The <img> tag should also contain the width and height attributes, which specifies the width and height of the image (in pixels):

 Example

<img src="india.jpg" width="500" height="600">
 
 
The alt Attribute

The required alt attribute for the <img> tag specifies an alternate text for an image, if the image for some reason cannot be displayed. This can be due to slow connection, or an error in the src attribute, or if the user uses a screen reader.

 Example

<img src="india.jpg" alt=" India Map">

 

The style Attribute

The style attribute is used to add styles to an element, such as color, font, size, and more.

Example

<p style="color:red;">This is a red paragraph.</p>
 
  
The lang Attribute

You should always include the lang  attribute inside the <html> tag, to declare the language of the Web page. This is meant to assist search engines and browsers.

The following example specifies English as the language:

<!DOCTYPE html>
 
<html lang="en">
 
<body>
...
</body>
 
</html>
 
 
The following example specifies English as the language and United States as the country: 
 
<!DOCTYPE html>
 
<html lang="en-US">
 
<body>
...
</body>
 
</html>
 
Country codes can also be added to the language code in the lang attribute. So, the first two characters define the language of the HTML page, and the last two characters define the country. 
 
 

 

 

 

 

 

 

 

 

 

 

No comments:

Post a Comment