iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

HTML Attributes

Attributes provide extra information about an element. They live inside the start tag, usually as name="value" pairs.

Anatomy of an attribute

<a href = "/about" > name value (quoted)
Fig 1. An attribute on an <a> element.

Common global attributes

These attributes can be used on almost any element:

AttributePurposeExample
idUnique identifier for the element.id="hero"
classSpace-separated list of class names, used by CSS.class="btn primary"
styleInline CSS for this element only.style="color:#04AA6D"
titleTooltip text shown on hover.title="Save"
langLanguage of the element's content.lang="en"
hiddenHides the element from rendering.hidden
data-*Custom data attributes you define yourself.data-user-id="42"
Note: Always quote attribute values. href=/about sometimes works, but href="/about" always does and is required as soon as the value contains spaces or special characters.

Example

Example
<!DOCTYPE html>
<html>
<head>
    <title>HTML Attributes</title>
</head>
<body>

<h1>HTML Attributes</h1>
<p>This is a demo page for the "HTML Attributes" lesson.</p>

</body>
</html>
Try it Yourself »

Exercise

Add the attribute that gives this link its destination.

<a ="https://laravel.com">Laravel</a>

Test yourself

Q1. Where do attributes appear?
Q2. Which attribute uniquely identifies an element on a page?
Q3. Which is the correct way to write an attribute?

Discussion

Loading…