Understanding HTML Attributes
HTML attributes provide additional information about an HTML element. They are written inside the opening tag and usually contain a name and a value.
Think of an HTML element as a person. The element tells us what the person is, while attributes give us additional information about that person.
For example, an
<a> element creates
a link. The
href attribute tells the
browser where the link should go.
HTML Attribute Syntax
An attribute is placed inside the opening tag and normally follows this structure:
<element attribute="value">
Content
</element>Simple Example
Here, the
href attribute tells the browser
where the link should navigate.
<a href="https://example.com">
Visit Example
</a>Common HTML Attributes
You will use these attributes frequently when building webpages.
idclasshrefsrcalttitle
Example: Using the id Attribute
The id attribute gives an
element a unique name.
<h1 id="main-title">
Welcome to ManaCoding
</h1>
Example: Using the class Attribute
The class attribute is commonly
used to apply CSS styles to elements.
<p class="intro">
Learn HTML with ManaCoding.
</p>Example: Image Attributes
The src attribute specifies the
image location, while alt
provides alternative text.
<img
src="logo.png"
alt="ManaCoding Logo"
>Try It Yourself
Edit the HTML code and click Run to see how attributes affect the webpage.