HTML Attributes

HTML Attributes

HTML attributes are extra pieces of information you add to an element's opening tag to configure its behaviour or appearance.


What Are HTML Attributes?

Attributes provide additional information about an element. They are always written inside the element's opening tag and never appear on the closing tag. For example, the href attribute tells an <a> element where to link, and the src attribute tells an <img> element which file to display.

Syntax

ℹ️

Attributes follow the pattern name="value". The name comes first, then an equals sign, then the value wrapped in quotes. Multiple attributes are separated by spaces.

An element with two attributes
<a href="https://myinternships.in" target="_blank">Find internships</a>

Quoting Rules

Values may use double quotes or single quotes, and double quotes are the most common convention. Quotes are technically optional for simple values that contain no spaces or special characters, but you should always quote attribute values to avoid bugs and keep markup readable.

Prefer quoted values
<!-- Recommended -->
<input type="text" name="city">

<!-- Works but fragile: unquoted value breaks with spaces -->
<input type=text name=city>

Boolean Attributes

Some attributes are boolean: their mere presence turns a feature on, and their absence turns it off. You do not need to give them a value. Examples include disabled, checked, required, readonly, selected and autofocus.

Boolean attributes need no value
<input type="checkbox" checked>
<button disabled>Submit</button>
<input type="email" required>
💡

A boolean attribute is true when present in any form (disabled, disabled="" or disabled="disabled"). To make it false, remove the attribute entirely.

Common Global Attributes

AttributeDescription
idA unique identifier for the element within the document
classOne or more space-separated class names used by CSS and JavaScript
styleInline CSS rules applied to the element
titleAdvisory text shown as a tooltip on hover
langThe language of the element's content, e.g. en or hi
hiddenBoolean attribute that hides the element from rendering
data-*Custom author-defined data attributes for scripting

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships