HTML attributes provide additional information about HTML elements. They are always specified in the start tag and usually come in name/value pairs like: name="value".
Some common attributes include id, class, style, title, and href. Each attribute serves a unique purpose and can influence the behavior or appearance of an element.
<!DOCTYPE html>
<html>
<body>
<a href="https://www.example.com" target="_blank">Visit Example</a>
</body>
</html>
Attributes allow you to customize elements, link CSS styles, and provide metadata. They are crucial for defining the structure and behavior of web pages.
Console Output:
Visit Example
The id attribute uniquely identifies an HTML element within a page. It is used for CSS styling and JavaScript manipulation.
Assigning a unique id to an element allows it to be targeted specifically by CSS or JavaScript functions.
<style>
#unique-element {
color: blue;
}
</style>
<p id="unique-element">This is a paragraph with a unique id.</p>
Console Output:
This is a paragraph with a unique id.
The class attribute is used to define a group of elements that can be styled and manipulated together using CSS and JavaScript.
An element can have multiple classes, allowing for complex styling and interactions.
<style>
.text-highlight {
background-color: yellow;
}
.bold-text {
font-weight: bold;
}
</style>
<p class="text-highlight bold-text">This paragraph has multiple classes.</p>
Console Output:
This paragraph has multiple classes.
The style attribute allows for inline CSS styling directly within an HTML element, providing a quick way to apply styles without external stylesheets.
Inline styles can override styles defined in external stylesheets.
<p style="color: red; font-size: 20px;">This paragraph is styled inline.</p>
Console Output:
This paragraph is styled inline.
The title attribute provides additional information about an element, often displayed as a tooltip when the mouse hovers over the element.
Using the title attribute can enhance accessibility by providing context to screen readers.
<p title="This is a tooltip">Hover over this paragraph to see the tooltip.</p>
Console Output:
Hover over this paragraph to see the tooltip.
The href attribute specifies the URL of the page the link goes to. It is used within <a> (anchor) tags.
Using the href attribute, you can create links to other web pages, documents, or resources.
<a href="https://www.example.com">Go to Example</a>
Console Output:
Go to Example
The alt attribute provides alternative text for an image if it cannot be displayed. It is crucial for accessibility and SEO.
Using descriptive alt text helps screen readers convey the content of an image to visually impaired users.
<img src="image.jpg" alt="A beautiful sunrise over the mountains">
Console Output:
A beautiful sunrise over the mountains
The src attribute specifies the source file for media elements like images, audio, and video. It defines the path to the resource.
Properly using the src attribute ensures that media files are correctly loaded and displayed on web pages.
<img src="path/to/image.jpg" alt="Descriptive text for image">
Console Output:
Descriptive text for image
Attributes like href
, src
, alt
, style
, and title
are foundational.
href
Attribute<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
</head>
<body>
<a href="https://www.example.com">Visit Example</a>
</body>
</html>
Explanation:
https://
) or relative URLs (/about.html
).src
AttributeThe src
attribute specifies the source file for an image, video, or script.
<!DOCTYPE html>
<html>
<head>
<title>Image Example</title>
</head>
<body>
<img src="image.jpg" alt="Beautiful Landscape">
</body>
</html>
Explanation:
Absolute URL: Complete path including domain name.
Example: https://example.com/page.html
Relative URL:Path relative to the current document.
Example: page.html
<!DOCTYPE html>
<html>
<head>
<title>URL Example</title>
</head>
<body>
<a href="https://www.example.com">Absolute URL</a>
<br>
<a href="relative-page.html">Relative URL</a>
</body>
</html>
alt
AttributeThe alt
attribute defines alternative text for images. It's essential for accessibility.
<img src="forest.jpg" alt="A lush green forest">
Explanation:
style
AttributeThe style
attribute adds inline CSS to elements.
<!DOCTYPE html>
<html>
<head>
<title>Styled Text</title>
</head>
<body>
<p style="color:blue; font-size:20px;">This is styled text</p>
</body>
</html>
lang
AttributeDefines the language of the document.
<html lang="en">
Output:
WikiGalaxy
title
AttributeAdds a tooltip that appears when hovering over the element.
<a href="https://www.example.com" title="Visit Example">Hover Over Me</a>
data-*
AttributesCustom data attributes for developers.
<div data-user-id="12345">User Information</div>
aria-*
AttributesImprove accessibility for screen readers.
<button aria-label="Close">X</button>
Newsletter
Subscribe to our newsletter for weekly updates and promotions.
Wiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterCompany
About usCareersPressCompany
About usCareersPressCompany
About usCareersPressLegal
TermsPrivacyContactAds PoliciesLegal
TermsPrivacyContactAds PoliciesLegal
TermsPrivacyContactAds PoliciesCompany
About usCareersPressCompany
About usCareersPressCompany
About usCareersPressLegal
TermsPrivacyContactAds PoliciesLegal
TermsPrivacyContactAds PoliciesLegal
TermsPrivacyContactAds PoliciesLegal
TermsPrivacyContactAds PoliciesAds Policies