HTML Attributes
- All HTML elements can include attributes.
- Attributes give extra information about an element or how it should behave.
- They are always written inside the start tag.
- Attributes are usually written as name/value pairs, like this: name="value"
General / Global Attributes
id AttributeUsed to give a unique identifier to an element. Helpful when styling with CSS or manipulating with JavaScript.
Example:
<p id="intro">Welcome to ByteAcademy!</p>Output:
Welcome to ByteAcademy!
class Attribute
Assigns one or more class names to an element, used for CSS styling or JavaScript functions.
Example:
<p class="highlight">This text uses a class.</p>Output:
This text uses a class.
style Attribute
Adds inline CSS styling directly to an element.
Example:
<p style="color: red; font-size: 18px;">Styled with inline CSS.</p>Output:
Styled with inline CSS.
title Attribute
Displays extra information when the user hovers over an element.
Example:
<p title="This is a tooltip!">Hover over this text.</p>Output:
Hover over this text.
Form Attributes
name AttributeGives a name to an input element, used to identify it when the form is submitted.
Example:
<input type="text" name="username" value="JohnDoe">Output:
placeholder Attribute
Displays a hint or example text inside an input field.
Example:
<input type="text" placeholder="Enter your name">Output:
value Attribute
Specifies the initial value of an input field.
Example:
<input type="text" value="Default Text">Output:
type Attribute
Defines the kind of input control (e.g., text, password, email, etc.).
Example:
<input type="password" placeholder="Enter password">Output:
disabled Attribute
Makes an element uneditable or unclickable.
Example:
<input type="text" value="Can't edit this" disabled>Output:
required Attribute
Marks an input field as mandatory before submitting the form.
Example:
<input type="email" placeholder="Enter your email" required>Output: