Links in HTML
In HTML, Links (Hyperlink) are created using the <a> (anchor) tag. It is used to navigate to other web pages, files, email addresses, or locations within the same page.
Syntax :
<a href="URL">Link Text</a>
Here 'URL' is the path or address of any webpages. 'Link Text' is the text that describes your link.
Common Attributes used in <a> tag :
href : It is used to specify the destination URL or address.
Example:
target : It is used to Specify where to open the linked document.
_self (default): It opens the web document in the same tab.
_blank : It opens the web document in a new tab or window.
Example:
rel : It is used to secify the relationship between the current page and the linked page.
Common values: noopener, noreferrer, nofollow etc.
Example:
title : It is used to add extra information (tooltip) when hovering over the link.
Example:
download : It is used to prompt the user to download the linked file instead of navigating to it.
Example:
hreflang : It is used to specify the language of the linked document.
Example:
type : It is used to specify the MIME type of the linked document.
Example:
Usage Examples
Best Practices
- We Use descriptive link text (avoid "click here").
- We always use rel="noopener noreferrer" with target="_blank" for security.
- We always use valid link not the broken link.
- We use the title attribute for additional context if needed.
- We use meaningful link text for better accessibility
Note :
The <a> tag is essential for navigation in HTML. We use its attributes to control link behavior, improve accessibility, and enhance user experience.
Image Tag in HTML
In HTML, The <img> tag is used to display images on a web page. It is a self-closing tag, meaning it does not require a closing tag. The <img> tag requires at least the src (source) and alt (alternative text) attributes.
Syntax
<img src="image_url" alt="description">
Here 'src' specifies the path or URL to the image file and 'alt' provides alternative text if the image cannot be displayed (important for accessibility and SEO).
Example
Common Attributes used in <img> tag :
width and height : It is used to set the size of the image (in pixels or percentage).
Example :
title : It is used to show a tooltip when the mouse hovers over the image.
Example :
loading : It is used to control the image loading behavior ( lazy for lazy loading).
Example :
Usage of <img> tag :
- image tag is used to display logos, photos, icons, and other images on web pages.
- It Use relative paths for images in your project folder, or absolute URLs for images hosted online.
Best Practices :
- We always use the alt attribute for accessibility and SEO.
- We use optimized images (small file size) for faster loading.
- We specify width and height to help browsers reserve space and avoid layout shifts.
- We store images in a dedicated folder (e.g., images/ ).
- We use appropriate file formats (i.e - .jpg , .png , .svg , .webp ).
- We use descriptive file names for images.
Note :
- The <img> tag does not have a closing tag.
- Browsers will display the image at the location of the <img> tag in your HTML.
Comments
Post a Comment