HTML Attributes


Attributes provide additional information about HTML elements. HTML attributes appear within the start tag and typically appear as name/value pairs.

<tagname attribute="value">Content</tagname>
 
html-attributes

Example

<a href="https://example.com">Visit Site</a>

HTML Attributes

Attribute Used With Description
href <a> URL of the link
src <img> Image source
alt <img> Alternative text for image
title All tags Tooltip text
style Most tags Inline CSS styling
id All tags Unique identifier
class All tags Grouping for styling with CSS or scripting
width, height <img>, <video>, etc. Set size
type <input>, <button> Defines input type (text, password, etc.)

Example

<img src="logo.png" alt="Company Logo" width="200" height="100"> 

Attributes

  • src: sets the file path
  • alt: text shown if image can't load
  • width and height: define size

Example 2: Input Field with Attributes

<input type="text" placeholder="Enter your name" id="username" class="input-box">

Attributes

  • type: input type
  • placeholder: hint text inside the field
  • id and class: used in CSS/JavaScript

Example 3: Link with Title

<a href="https://google.com" title="Go to Google">Google</a>

notepad
  • Attribute names are case-insensitive, but lowercase is preferred
  • Always enclose values in quotes
  • Some boolean attributes like checked, disabled, readonly don’t need values



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.