3.html-attributes.md
Quiz
~/ hackweb.dev
...
~/
/tutorials
/en/html/html-attributes/edit
~ Contribute
Suggest a correction or improvement. The author reviews it before it goes live.
Loading...
en/tutorials/html/3html-attributes
# HTML Attributes Attributes are extra information attached to an element. They live inside the opening tag and follow `name="value"`. ## Anatomy of an attribute ```html <a href="https://example.com" target="_blank">Visit</a> ``` Every attribute has a name and a value. The value is usually wrapped in double quotes. ## Common attributes - `href` — link destination on `<a>` - `src` — image or script source - `alt` — descriptive text for images - `class` — a CSS hook (many elements can share it) - `id` — a unique identifier ```html <img src="cat.png" alt="A cat sleeping" class="photo" id="hero-cat" /> ``` ## Boolean attributes Some attributes have no value — their presence alone is the value. ```html <input type="text" disabled /> <button disabled>Not clickable</button> <input type="checkbox" checked /> ``` - `disabled` — element is not interactive - `checked` — checkbox starts selected - `required` — field must be filled ## data-* attributes Any attribute prefixed with `data-` is available to JavaScript and never affects rendering. ```html <button data-tooltip="Save your work">Save</button> ```
Submit suggestion
cancel